Question

BPM question

  • 6 June 2023
  • 3 replies
  • 88 views

Userlevel 1

We are looking to make a change in our purchasing process.   We want the system to check to make sure there is set Standard Cost for an inventory part, before the system will allow the PO to be Approved.

Not sure what all would have to be done, but wondering if anyone has done something like this and would share what they have done.   

Any guidance or suggestion would be appreciated.

 

 


3 replies

Userlevel 3

We do not perform a check on the PO tables, but we use the following code for releasing a job to our manufacturing group.  Modifying to use the PO tables, instead of the JobHead table, so not be complicated:

 

foreach(var jhed in (from jhedrow in ttJobHead  
  where (string.Equals(jhedrow.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase) || string.Equals(jhedrow.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase))
  select jhedrow ))
  {
    foreach( var part in (from partrow in Db.Part
      where (jhed.Company == partrow.Company && jhed.PartNum == partrow.PartNum)
      select partrow))
      {
        foreach( var pcst in (from pcstrow in Db.PartCost
        where (jhed.PartNum == pcstrow.PartNum && pcstrow.CostID == "1")
        select pcstrow))
        {
          if (jhed.JobReleased == true) /*Job is being Released*/
          {
            if (part.ClassID != "REP") /*Part is not a Repair Part*/
            {
              jhed.LockQty = true ; /*Set LockQty flag to TRUE*/
              if (pcst.StdMaterialCost == 0) /*Check for a valid Stnd Cost*/
               {
                this.PublishInfoMessage("Excuse me, but the Job you are trying to release to Production, does not contain a Standard Cost for the item you are building.  Please contact Purchasing to have this issue investigated, and Have a Nice  Day." ,Ice.Common.BusinessObjectMessageType.Error, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
                  jhed.JobReleased = false; /*Reset Released flag to FALSE*/
                  jhed.LockQty = false; /*Reset LockQty flag to FALSE*/
               }
               else /*Standard Cost is Valid*/
               {
               jhed.UserDate1 = DateTime.Now; /*Capture Job Release Date*/
               }
            }
          }
        }
    }
}
 

Contact me if you have questions.

Glenn

You could also write a BPM using a query to check for a std cost > 0.  If there are no records in the query you could put a stop message on the screen telling the user there is no standard cost for that part and not allow the line to be entered.

Userlevel 3

Note, one of my hobbies is making code more efficient. The code above has several inefficiencies which can be corrected.

  1. too much looping (foreach) when none of it is required
  2. reading too much data, which loads entire records, when all you needed was one fact part is not a repair part, or part has a standard cost). by using the “any” search, the system doesnt return the entire record, but simply returns a true/false

below is the code (untested so there might be typos).

 

 

var jhed = ttJobHead.Where(x=>  

        (x.RowMod == IceRow.ROWSTATE_Updated ||

         x.RowMod == IceRow.ROWSTATE_Added) &&

        x.JobReleased).FirstOrDefault(); //we only need to work with Released jobs, so only find them.

 

if (jhed != null){  //if something is found:

    bool PartNOTRepairPart part = Db.Part.Any(x=>

        x.Company == jhed.Company &&

        x.PartNum == jhed.PartNum &&

        x.ClassID != "REP");  //returns TRUE if the class ID <> REP

    )

    if (PartNOTRepairPart) {

        bool PartHasStandardCost= Db.PartCost.Any(x=

            x.Company == jhed.Company &&

            x.PartNum == jhed.PartNum &&

            x.CostID == "1" &&

            x.StdMaterialCost != 0);   //returns TRUE if the part has a standard cost

 

        if (PartHasStandardCost) {

            jhed.UserDate1 = DateTime.Now; /*Capture Job Release Date*/

            jhed.LockQty = true; /*Set LockQty flag to TRUE*/

        }else{

            this.PublishInfoMessage("Excuse me, but the Job you are trying to release to Production, does not contain a Standard Cost for the item you are building.  Please contact Purchasing to have this issue investigated, and Have a Nice  Day." ,Ice.Common.BusinessObjectMessageType.Error, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");

            jhed.JobReleased = false; /*Reset Released flag to FALSE*/

            jhed.LockQty = false; /*Reset LockQty flag to FALSE*/

       

        }

    }

}

 

Reply