Erp.Contracts.BO.JobClosing

Hi, im trying to use the JobClosing method to close/open jobs in a BPM but no luck so far. No error returned and strOut string at the end is blank. Any idea? Here is code below. Thanks

var JobClosingTable = new Erp.Tablesets.JobClosingTableset();
Erp.Contracts.JobClosingSvcContract hC = null;
hC = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobClosingSvcContract>(Db);
string strOut = “”;
bool blnInput = false;

          if (hC != null) 
          { 
	JobClosingTable = new Erp.Tablesets.JobClosingTableset();

             hC.GetNewJobClosing(ref JobClosingTable);
            
            if (JobClosingTable != null) 
            { 
              
              var qDS = JobClosingTable.JobClosing;

              foreach(var row in qDS)
              {
                row.JobNum = strJobNum;
                row.QuantityContinue = 1;
                row.JobClosed = true;
                row.ClosedDate = DateTime.Now;
                
                hC.PreCloseJob(ref JobClosingTable, out blnInput);
                hC.CloseJob(ref JobClosingTable, out strOut);
                
              }
              
              
            }
            
           }

Have you tried outputting to the Application Log at different parts in the code to confirm what all runs?

Ice.Diagnostics.Log.WriteEntry(“Message Here”);

I’ve outputed messages (PublishInfoMessage) between each line to make sure that everything runs. I also have a try catch (which is not catching anything).

thanks,

What messages are you getting in your output?

Brad,

im outputing sequencial numbers that im hardcoding to spot where the code is at.

Also, as I mentioned, the strOut string is not outputing anything from hC.CloseJob(ref JobClosingTable, out strOut);

Thanks,

I believe the OnChangeJobNum is missing, I have this example when closing with Backflush

Erp.Contracts.JobClosingSvcContract hJobC = null;
hJobC = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobClosingSvcContract>(Db);

if (hJobC != null)
{
//Closing with Backflush
hJobC.GetNewJobClosing(ref dsJobClosing);
hJobC.OnChangeJobNum(oper.Key1, ref dsJobClosing, out msg);

var jobC_Row = (from x in dsJobClosing.JobClosing
                where x.RowMod != ""
                select x).FirstOrDefault();
if (jobC_Row != null)
{
	jobC_Row.BackFlush = true;
	jobC_Row.JobComplete = true;
	jobC_Row.JobCompletionDate = DateTime.Today;
	hJobC.OnChangeJobCompletion(ref dsJobClosing);
	hJobC.PreCloseJob(ref dsJobClosing, out reqInput);
	hJobC.CloseJob(ref dsJobClosing, out msg);                                
}

}
hJobC = null;

Make sure your RowMod is properly set.

Thanks! It was what I was missing.

Hello Martin,

would you be able to share your BPM with us? I’m trying to implement a method to close the jobs when a pack is shipped(Ready to invoice is checked). Thanks.

Edit: Or the C# custom code.

Sure!

Erp.Contracts.JobClosingSvcContract hC = null;
hC = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobClosingSvcContract>(Db);
string strOut = "";
bool blnInput = false;
string msg="";

			  if (hC != null) 
              { 
		JobClosingTable = new Erp.Tablesets.JobClosingTableset();
							  
							  
                hC.GetNewJobClosing(ref JobClosingTable);
                hC.OnChangeJobNum(*YOURJOBNUM*, ref JobClosingTable, out msg);
               
                
                if (JobClosingTable != null) 
                { 
                  
                  var qDS2 = JobClosingTable.JobClosing;

                  foreach(var rowJob2 in qDS2)
                  {
                   //re-opening jobs
                    rowJob2.QuantityContinue = 1;
                    rowJob2.JobClosed = false;
                    rowJob2.ClosedDate = null;
                    rowJob2.JobComplete = false;
                    rowJob2.JobCompletionDate = null;
                    
                    hC.OnChangeJobCompletion(ref JobClosingTable);
                    hC.PreCloseJob(ref JobClosingTable, out blnInput);
                    hC.CloseJob(ref JobClosingTable, out strOut);
                    
                  }
                  
                  
                }
                
               }```
2 Likes

Thank you very much friend! :hugs:

Hi - apologies for resurrecting such an old thread and thank you for posting the code.

I’m in the process of learning using custom code in bpms and data directives.

Question - how does one know/figure out to do this -

hC.GetNewJobClosing(ref JobClosingTable);
hC.OnChangeJobNum(YOURJOBNUM, ref JobClosingTable, out msg);

It looks like this populates the jobClosingTable with data from the job number - but outside of google and trial and error - I don’t know where to look for this info.

When I enable tracing - I get some references, but not seemingly all and googling seems to yield results - so how did you all figure this out in the first place?

thank you for any advice

Paul