Not sure if this is the right forum, not seeing a lot of posts in the code review section.
Trying to fire a BPM when a job is released to warn that there are operations that are missing times entirely, so zeros for setup and production. So, want to loop on the operations based on the job modified.
Am I close with this bit of C# to take the JobHead job num and then cut across to JobOper to start looping and summing up the times?
foreach (var ttJobHead_xRow in ttJobHead)
{
foreach (var row in (from JobOper_Row in Db.JobOper
where ttJobHead_xRow.Company == JobOper_Row.Company && ttJobHead_xRow.JobNum = JobOper_Row.JobNum
select JobOper_Row))
{
// Do some variable sums
}
}
That’s the right direction for looping through the JobOpers in a job within a BPM. Watch out for the syntax issue with the equals sign when comparing the JobNum in the where clause though.
If you’re only checking to see if certain conditions are met, you may want to check out Linq’s Any() method instead. Makes things easier and probably performs faster too (haven’t benchmarked, but Linq methods are very optimized).
Something like this:
bool zeros = false;
foreach (var ttJobHead_xRow in ttJobHead)
{
System.Linq.IQueryable<Erp.Tables.JobOper> rows =
(
from JobOpers in Db.JobOper
where ttJobHead_xRow.Company == JobOpers.Company && ttJobHead_xRow.JobNum == JobOpers.JobNum
select JobOpers
);
if (rows.Any(r => r.EstProdHours == 0 || r.EstSetHours == 0)) //use anything you want here, I just have these two as an example
zeros = true;
}
if (zeros)
{
/* do something */
}
Many thanks Jason, that got me there and I can utilize this for other uses. I modified to be an AND operator for zero on Production and Setup and added a check for not being a subcontract operation. Added a popup message.
As a side question, if I wanted to pipe the value of something within the custom code to a BPM variable to then perform additional actions in the BPM flow, is that possible? i.e. Push the resultant value of zeros value into a variable to use as a conditional step later.
bool zeros = false;
foreach (var ttJobHead_xRow in ttJobHead)
{
System.Linq.IQueryable<Erp.Tables.JobOper> rows =
(
from JobOpers in Db.JobOper
where ttJobHead_xRow.Company == JobOpers.Company && ttJobHead_xRow.JobNum == JobOpers.JobNum
select JobOpers
);
if (rows.Any(r => r.EstProdHours == 0 && r.EstSetHours == 0 && r.SubContract == false))
zeros = true;
}
if (zeros)
{
this.PublishInfoMessage("An operation has zero times for Setup and Production!", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}
Absolutely. I do that all the time even if it’s just so that I can have the exception handling through the BPM object rather than having to write it out by hand.
Right-click the space where you want to insert the variable into the code and any declared variables will be available through the Variables option. Or, if you don’t want to declare your own variables, you can utilize the built-in Call Context objects.