Method Directive - Update QuoteDtl field

Hi

I need to update a field in post process with a Method directive. Im looking for an Update MD but cannot find one related to the QuoteDtl table / adapter.

Which directive should i use to update the table when a field changes?

Thanks

Method directives aren’t tied to “Tables”, they are tied to methods. (programs). So you would be probably looking at the Quote namespace, and the Update method.

Data directive look at the specific tables. We generally view data directives as a last resort because they fire a lot and usually you can do what you need to with method directives.

3 Likes

Hi

sorry it took a while to respond.

So i have made a Method Directive on the Quote BO using the Update method. Simply put, i have tried to populate the QuoteDtl.ProjectID with QuoteHed.Project_c but i get an error saying the temp table is not available. I guess thats because im not making any changes to the QuoteDtl at the time of the MS being invoked because the change is on the QuoteHed.

In the Quote Entry customization, i can successfully populate the QuoteHed.Project_c with code that is getting the ProjectID from the Project Adapter found on a Project search button. There must be a reasonably straight forward method to update the QuoteDtl table seeing as its related to the QuoteHed table by Company & QuoteNum? In plain old SQL, its a breeze

DECLARE @CompanyName VARCHAR(50) = NULL;
DECLARE @QuoteNum VARCHAR(50) = NULL;
DECLARE @ProjectID VARCHAR(50) = NULL;

UPDATE QuoteDtl
SET ProjectID = @ProjectID
WHERE QuoteDtl.QuoteNum = @QuoteNum AND QuoteDtl.CompanyName = @CompanyName

Select * from QuoteDtl WHERE QuoteDtl.QuoteNum = @QuoteNum AND QuoteDtl.CompanyName = @CompanyName

Thanks :slight_smile:

Yes, you’re correct, the system isn’t going to send the info for tables that don’t change. If it’s just a UD field, you can just use the the DB context to write to the table, which is in essence the same as doing direct SQL queries. The other option is do a GetByID() call in the method directive will will populate your whole data set and then you can make your changes. If you can make conditions so that doesn’t run when it’s not needed, that can be a viable option too. You just do want that running all the time, because it would be a lot of unneeded data if you didn’t need to update it.

Seems like a a lot of unnecessary work for what it is… Outside of Epicor, this is a real easy method to put together, i do them all the time…

On the Quote Entry form, i can see populated fields for both QuoteHed & QuoteDtl so there must be a QuoteDtl davaview or adapter available. I dont know what a GetByID is yet or how to implement that in Epicor.

So here are my 2 options

Option 1 - Code on the Quote Entry Script editor
This first block of code exists in the form from a 3rd party contractor. It gets the ProjectID from a Project Adapter and successfully adds the value to the QuoteHed.Project_c field. At this stage, its the only field being changed

EpiDataView edvQH = ((EpiDataView)(this.oTrans.EpiDataViews["QuoteHed"]));
System.Data.DataRow edvQHR = edvQH.CurrentDataRow;
if ((edvQHR != null))
{
   edvQHR.BeginEdit();
   edvQHR["Project_c"] = adapterRow["ProjectID"];
   edvQHR.EndEdit();

So its fair to say i ‘should’ be able do the same to update the QuoteDtl table because they both exist on the Quote Entry form and they are both in the oTrans transaction but thats not the case here. It doesnt error, it just doesnt do anything at all…

EpiDataView edvQD = ((EpiDataView)(this.oTrans.EpiDataViews["QuoteDtl"]));
System.Data.DataRow edvQDR = edvQD.CurrentDataRow;
if ((edvQDR != null))
{
   edvQDR.BeginEdit();
   edvQDR["ProjectID"] = adapterRow["ProjectID"];
   edvQDR.EndEdit();

Option 2 - Method Directive on Quote.Update
i put this code together. It doesnt do anything if the quoteDtl table is filtered with RowMod == “U” and without this line, it throws a null exception error

var currentCompany = callContextClient.CurrentCompany;
var currentUser = callContextClient.CurrentUserId;

var qn = (from r in ttQuoteHed where r.RowMod == "U" select r).FirsrOrDefault();
var quotNum = Convert.ToInt32(qn.QuoteNum);

if (quotNum != null)
{
   var ProjectID = (from r in Db.QuoteHed
                              where r.Company == currentCompany &&
                                    r.QuoteNum == quotNum
                              select r.Project_c).DefaultIfEmpty("").FirstOrDefault();

   var QuoteDtlRow = (from r in Db.QuoteDtl.With(Lockhint.UpdLock)
                                    where r.Company = currentCompany &&
                                          r.QuoteNum == quotNum
                                    select r).FirstOrDefault();

   if (quoteDtlRow != null)
   {
      QuoteDtlRow.ProjectID = projectID;
      Db.Validate();
   }
}

My objective
Populate the QuoteHed.Project_c field and the QuoteDtl.ProjectID field with the same ProjectID value