Foreach criteria - BPM Code

This is custom code on a post processing method directive for OrderJobWizard.CreateJobs. I’m trying to pair down the results to only the jobs being created using Order Job Wizard. Since we create jobs for every release I’m using the ttJWOrderRel table. I’m testing using an order with 2 lines and 2 releases. I’m creating jobs for both releases of 1 line, my code returns the would-be job numbers of all 4 releases, rather than just the 2 releases I’m attempting to create jobs from.

Here’s the code:

foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel select row))
{

  var Rel =    (from por in Db.OrderRel
                where por.Company == Session.CompanyID
                && por.OrderNum == ttJWOrderRel_Row.OrderNum
                && por.OrderLine == ttJWOrderRel_Row.OrderLine
                && por.OrderRelNum == ttJWOrderRel_Row.OrderRelNum
                select new {por.Company, por.OrderNum, por.OrderLine, por.OrderRelNum}).ToArray();
                
if (Rel != null)
{

    foreach(var Rels in Rel)
    {
          
        int OrderNum = Rels.OrderNum;
        int OrderLine = Rels.OrderLine;
        int OrderRelNum = Rels.OrderRelNum;

        string job = (OrderNum + "-" + OrderLine + "-" + OrderRelNum).ToString();

        this.PublishInfoMessage(job, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
       
}
}
}       

Anyone have any suggestions on how to pair down the results to only the releases I’m cutting jobs for?

I have tried using an IF statement after my first foreach line.

foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel select row))
{

if(ttJWOrderRel_Row.RelJobChkBox == true)
{

This didn’t seem to solve it.

Modify the line above to only be where the checkbox is true (I don’t recall the name of the field, but Field Help should show it).

Like this? I could have swore I’ve tried this once.

foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel where row.RelJobChkBox == true select row))

I tried this:

foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel where row.RelJobChkBox == true select row))

But it didn’t seem to work, the jobs are made, but I’m not getting a message like I should be.

Try doing It on a data directive on JobHead Table.

You could then use a condition widget:

Conditions:
1.At least one row added to ttJobHead
2. where CurrentContext.AssemblyID = ERP. UI.OrderJobWiz

Sorry this is off the top of my head as not current in the office.

Hope this helps.

1 Like

This should work. What is the full code you are using and what is the expected output?

What I posted earlier is the full code, for the time being. Once I have the correct job numbers being returned I’ll be using them in another foreach linq statement to grab JobOper fields, AssemblySeq and OprSeq, to create purchase orders with. I tried that foreach statement and it’s not working for me, if I remove where row.RelJobChkBox == true I do get the message box with the would-be job numbers.

I have working code to create the Purchase Orders with, from a previous project, but I can’t seem to pair down my results to only the jobs actually being made.

@ridgea, while that is cool, and you taught me something new, Data Directives don’t work for what I’m trying to do.

1 Like

Got it. Was this a Pre-Processing or Post Processing Directive?
I would think you need to collect a List in Pre-Processing, but perform your work in Post-Processing.

This is from my order entry screen:
image

Order Job Wizard:

I’m creating 2 jobs, 123673-1-1 and 123673-1-2, but instead my code returns all 4 would be jobs including 123673-2-1 and 123673-2-2

Aaand, I just got your reply. This is on Post-Processing. I’m not entirely sure how to build the list in pre-processing.

Here is the list of possible fields. I would offer that you have selected the wrong one (although I have not run a trace):
image

Here’s what my trace says:

<tracePacket>
  <businessObject>Erp.Proxy.BO.OrderJobWizImpl</businessObject>
  <methodName>CreateJobs</methodName>
  <appServerUri>net.tcp://ccb-erptest2/ERP102500/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>10/22/2020 11:55:15:3195690 AM</localTime>
  <threadID>1</threadID>
  <correlationId>ed0754ba-bcd2-4086-8ee7-50dffb679748</correlationId>
  <executionTime total="2876" roundTrip="2868" channel="0" bpm="0" other="8" />
  <retries>0</retries>
  <parameters>
    <parameter name="ds" type="Erp.BO.OrderJobWizDataSet">
      <OrderJobWizDataSet xmlns="http://www.epicor.com/Ice/300/BO/OrderJobWiz/OrderJobWiz" />
    </parameter>
    <parameter name="pErrorMessages" type="System.String"><![CDATA[]]></parameter>
  </parameters>
  <paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">

      <changedValue tableName="JWJobOrderDtl" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>

      <changedValue tableName="JWJobOrderDtl" rowState="Modified" rowNum="1" colName="JobChkBox"><![CDATA[False]]></changedValue>

      <changedValue tableName="JWJobOrderDtl" rowState="Modified" rowNum="1" colName="RowMod"><![CDATA[U]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="0" colName="RelDetailChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="0" colName="RelScheduleChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="0" colName="RelJobChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="0" colName="RelReleaseChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="1" colName="RelDetailChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="1" colName="RelScheduleChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="1" colName="RelJobChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="1" colName="RelReleaseChkBox"><![CDATA[True]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="1" colName="RowMod"><![CDATA[U]]></changedValue>

      <changedValue tableName="JWOrderRel" rowState="Modified" rowNum="3" colName="RowMod"><![CDATA[U]]></changedValue>

    </paramDataSet>
  </paramDataSetChanges>
</tracePacket>

Did a little more testing, checked the values of RelReleaseChkBox and JobChkBox using:

foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel select row))
{

 string RelJobChkBox = ttJWOrderRel_Row.RelJobChkBox.ToString(); 
 string RelReleaseChkBox = ttJWOrderRel_Row.RelReleaseChkBox.ToString();

this.PublishInfoMessage("RelJob = " + RelJobChkBox + "\nRelRelease = " + RelReleaseChkBox, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

and got this for each row… well now I’m really stuck haha

image

Okay, so I decided to tackle this a little differently and I think I may have gotten some traction. Logically, since this is Post-Process, these jobs already exist when the code runs, right? I believe they are, so instead of linqing to OrderRel, let’s try JobProd instead. Boom, got it.

I’m now only returning jobs that are actually made, as I’m looking at the JobProd table, grabbing the job number from there; rather than trying to string together the job number from OrderRel table.

 foreach (var ttJWOrderRel_Row in (from row in ttJWOrderRel select row))
{

  var JobProd =    (from jp in Db.JobProd
                where jp.Company == Session.CompanyID
                && jp.OrderNum == ttJWOrderRel_Row.OrderNum
                && jp.OrderLine == ttJWOrderRel_Row.OrderLine
                && jp.OrderRelNum == ttJWOrderRel_Row.OrderRelNum
                select new {jp.Company, jp.OrderNum, jp.OrderLine, jp.OrderRelNum, jp.JobNum}).ToArray();
                
if (JobProd != null)
{

    foreach(var Rels in JobProd)
    {
          
        string JobNum = Rels.JobNum;

        this.PublishInfoMessage("Job: " + JobNum, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
       
}
}
} 

@Jason_Woods, thanks again for the help and holding my hand, I knew I would get it eventually.

That works too :slight_smile:

1 Like