Methods Directive not completing in correct order

,

I have a Method Directive enabled on CreateOrder for Quotes that is creating new parts when a certain radio button is marked to “Yes”. It is a Post Process and there are 3 execute custom code. 1st one creates Part record, 2nd one created PartPlant record and 3rd one creates PartWhse. The issue is the PartWhse is running before the PartPlant record and cannot get it to go last.

Any suggestions would be great. I was trying to use callContextBpmData to try and have it go in order but not working.

It’s likely you don’t have the sequence set correctly. They run in numerical order.

They are all inside one Directive. It does not follow if separate even using the Order No for the directive to start at different times.
image

I suppose it depends on what the code is doing inside.

Part Create code:
Erp.Tables.QuoteDtl QuoteDtl;

foreach (var QuoteDtl_iterator in (from QuoteDtl_Row in Db.QuoteDtl
where QuoteDtl_Row.Company == Session.CompanyID
&& QuoteDtl_Row.QuoteNum == callContextBpmData.Number06
&& QuoteDtl_Row.NewPart_c == “Yes”
select QuoteDtl_Row))

{
var QuoteDtlRow = QuoteDtl_iterator;

  if (QuoteDtlRow != null)
    {
      Part newpart = new Part();
      Db.Part.Insert(newpart);
      newpart.Company = Session.CompanyID;
      newpart.PartNum = QuoteDtlRow.PartNum;
      newpart.PartDescription = QuoteDtlRow.LineDesc;
      newpart.TypeCode = QuoteDtlRow.TypeCode_c;  
      newpart.ProdCode = QuoteDtlRow.ProdCode;
      newpart.RefCategory = QuoteDtlRow.RefCat_c;
      newpart.Print_c = QuoteDtlRow.Print_c;
      newpart.Material_c = QuoteDtlRow.Material_c;
      newpart.Diameter_c = QuoteDtlRow.Diameter_c;
      newpart.Lth_c = QuoteDtlRow.Lth_c;
      newpart.Wdth_c = QuoteDtlRow.Wdth_c;
      newpart.CenterThick_c = QuoteDtlRow.CenterThick_c;
      newpart.Thickness_c = QuoteDtlRow.Thickness_c;
      newpart.EdgeThick_c = QuoteDtlRow.EdgeThick_c;
      newpart.CSM_c = QuoteDtlRow.CSM_c;
      newpart.Chips_c = QuoteDtlRow.Chips_c;
      newpart.Edges_c = QuoteDtlRow.Edges_c;
      newpart.Chamfers_c = QuoteDtlRow.Chamfers_c;
      newpart.Coating_c = QuoteDtlRow.Coating_c;
      newpart.Centration_c = QuoteDtlRow.Centration_c;
      newpart.Wedge_c = QuoteDtlRow.Wedge_c;
      newpart.TIR_c = QuoteDtlRow.TIR_c;
      newpart.TrnWve_c = QuoteDtlRow.TrnWve_c;
      newpart.Parallel_c = QuoteDtlRow.Parallel_c;
      newpart.DocReq_c = QuoteDtlRow.DocReq_c;
      newpart.PackReq_c = QuoteDtlRow.PackReq_c;
      newpart.MatCerts_c = QuoteDtlRow.MatCerts_c;
      newpart.SurfaceQual_c = QuoteDtlRow.SurfaceQual_c;
      newpart.SurfaceAcc_c = QuoteDtlRow.SurfaceAcc_c;
      newpart.SurfaceRough_c = QuoteDtlRow.SurfaceRough_c;
      newpart.ClearApert_c = QuoteDtlRow.ClearApert_c;
      newpart.Radius_c = QuoteDtlRow.Radius_c;
      newpart.Spec1R2_c = QuoteDtlRow.Spec1R2_c;
      newpart.SurfQual2_c = QuoteDtlRow.SurfQual2_c;
      newpart.SurfAcc2_c = QuoteDtlRow.SurfAcc2_c;
      newpart.SurfRough2_c = QuoteDtlRow.SurfRough2_c;
      newpart.ClearApert2_c = QuoteDtlRow.ClearApert2_c;
      newpart.Spec2R1_c = QuoteDtlRow.Spec2R1_c;
      newpart.Spec2R2_c = QuoteDtlRow.Spec2R2_c;
      newpart.CS1_c = QuoteDtlRow.CS1_c;
      newpart.CS2_c = QuoteDtlRow.CS2_c;
      newpart.CS3_c = QuoteDtlRow.CS3_c;  

      callContextBpmData.Number07 = QuoteDtlRow.QuoteNum;          

          this.PublishInfoMessage("QuoteDtl.PartNum: " + QuoteDtlRow.PartNum + " " + " QuoteDtl.QuoteNum: " + QuoteDtlRow.QuoteNum + " newpart.PartNum: " + newpart.PartNum , Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "QuoteDtl-Post1", "CreateOrder");
    }

}

PartPlant Create code:
Erp.Tables.QuoteDtl QuoteDtl;

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
foreach (var QuoteDtl_iterator in (from QuoteDtl_Row in Db.QuoteDtl
where QuoteDtl_Row.Company == Session.CompanyID
&& QuoteDtl_Row.QuoteNum == callContextBpmData.Number07
&& QuoteDtl_Row.NewPart_c == “Yes”
select QuoteDtl_Row))
{
var QuoteDtlRow = QuoteDtl_iterator;

      if (QuoteDtlRow != null)
        {
          PartPlant newpartplant = new PartPlant();
          Db.PartPlant.Insert(newpartplant);
          newpartplant.Company = Session.CompanyID;
          newpartplant.Plant = "MfgSys";
          newpartplant.PartNum = QuoteDtlRow.PartNum;
          newpartplant.PrimWhse = "Main"; 
          newpartplant.SourceType = QuoteDtlRow.TypeCode_c;
      
      callContextBpmData.Character10 = newpartplant.PartNum;
      
      //callContextBpmData.Number07 = QuoteDtlRow.QuoteNum;
      
            this.PublishInfoMessage("QuoteDtl.QuoteNum: " + QuoteDtlRow.QuoteNum.ToString() + " QuoteDtl.PartNum: " + QuoteDtlRow.PartNum + " newpartplant.Part: " + newpartplant.PartNum + " newpartplant.Plant: " + newpartplant.Plant + " BPMData.C10: " + callContextBpmData.Character10, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "Quote-Post2", "CreateOrder-Post");
        }
  }
  Db.Validate();
  txScope.Complete();

}

PartWhse Create Code:
using (var txScope = IceDataContext.CreateDefaultTransactionScope())
{
var PartWhse = from pw in Db.PartWhse.With(LockHint.UpdLock)
where pw.Company == Session.CompanyID
&& pw.PartNum == callContextBpmData.Character10
select pw;

     this.PublishInfoMessage("CCBpmData.C10: " + callContextBpmData.Character10, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "QuoteDtl-Post2", "CreateOrder");
      
  if (PartWhse != null)
    {
      PartWhse newpartwhse = new PartWhse();
      Db.PartWhse.Insert(newpartwhse);
      newpartwhse.Company = Session.CompanyID;
      newpartwhse.PartNum = callContextBpmData.Character10;
      newpartwhse.WarehouseCode = "Main";
      
           this.PublishInfoMessage("newpartwhse.PartNum: " + newpartwhse.PartNum + " newpartwhse.WarehouseCode: " + newpartwhse.WarehouseCode, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "QuoteDtl-Post3", "CreateOrder");
    }
    
    Db.Validate();
    txScope.Complete();

}

I attached the code for all 3 custom code.

Thanks. I would offer that you should use the Business Object Method instead of the “Insert”.

i tried adding Erp.Contract.BO.Part to directive, but i get the following error:

There is at least one compilation error.
CreateOrder.CommonTypes.cs(346,33): error CS0433: The type ‘PartSubsTable’ exists in both ‘Erp.Contracts.BO.Part, Version=10.2.300.0, Culture=neutral, PublicKeyToken=5d3fa3c7105d7992’ and ‘Erp.Contracts.BO.Quote, Version=10.2.300.0, Culture=neutral, PublicKeyToken=5d3fa3c7105d7992’

I wish there was a more viable solution for these. Can you use a CallContext and a Data Directive with Code and a BO?

Unfortunately if I set a CallContext in Method Directive, the Data Directive does not see it or find it.

Really?!? That’s a surprise. I guess I don’t recall if I’ve used that before.
Can you use a Data Directive on OrderDtl when a new record is added with a QuoteNum?

i just tried it again and the QuoteDtl Standard Directive did pick up on the CallContext.

Perfect. That should work then.

1 Like

But the Standard Directive did not start when call the Create Order. Only when changed Quote Detail.

nope. I need the Data Directive called or started when CreateOrder is launched.

The orderdtl Standard Directive found the callContext record and I was able to add the Erp.Contracts.BO.Part to the References section. But the standard does not have the option for “Invoke BO Method”.

Explore DeferredUpdate there is reference to the method here InvTransferSvcContract.CommitTransfer fails when transferring the same part one after the other - #24 by josephmoeller

When I add that code in I get an error: "The type or namespace name ‘Internal’ does not exist in the namespace ‘Erp’ (Are you missing an assembly reference?)