Having trouble with BPM condition, and custom code

,

My overall goal with this BPM is to detect whether someone has changed the POHeader.PromiseDate field, and if they have prompt the user to change the PORel.PromiseDate in the release lines to reflect the change. I have set it up as a method directive preprocessing, since I only want it to run when changed by an updatable query.

image

My first issue is the condition circled in red. I have it set up such that it should return true when the PromiseDate field has been changed.
image
For some reason it is not returning true. I do not understand why. Maybe I am misunderstanding the purpose of the condition?

My second issue is with the code I am using to update he PORel fields.

> foreach(var POHed in ttPOHeader.Where(pt => pt.Updated() || pt.Added()))
> {
> 	var PORel = (from pl in Db.PORel where pl.Company == POHed.Company && pl.PONum == POHed.PONum select pl);
> 	foreach(var rel in PORel)
> 		{
> 		rel.PromiseDt = POHed.PromiseDate;
> 		Db.Validate();
> 		}
> }

When the code does run, none of the fields are changed. Again, despite my best attempts I cannot figure out why it does not work as intended.

I might going about this entirely the wrong way, so any feedback would be appreciated.

Hello Kevin,

It is an annoying behavior, but I do have the same issues. Even after just adding messages before the condition were not showing !
It is as the DLL of your BPM has not been replaced. The way I overcome this is I do a recycle IIS via the admin console. Make sure there is no active tasks running prior to do this…
Once done the BPM behaves correctly.

Pierre

I solved the custom code bit by removing the Update() line as well as the .Where(…).

@Hogardy Thanks for the advice. I will see if that fixes my condition problem. I suspect, though, that I am using the condition in an unintended way.

I replaced the condition with a custom code validation check. It now works the way I want. If anyone finds this post helpful, let me know! :slight_smile:

foreach(var POHedr in ttPOHeader)
{
	var POHed = (from pl in Db.POHeader where pl.Company == POHedr.Company && pl.PONum == POHedr.PONum && pl.PromiseDate != POHedr.PromiseDate select pl);
	foreach(var hed in POHed)
		{
				return true;
		}
}
return false;
1 Like

(if anyone has a better way of checking if the length of the POHed dataset is larger than 0 let me know)

POHed.Count() > 0

1 Like

Can a similar code be written to condition for two fields at once? Like I need a condition on the ttPODetail.PartQtyBearing and the ttPORel.TranType fields and the regular condition caller isn’t working - so I figured I could use the custom code callers to do this.

ttPODetail.PartQtyBearing = true && ttPORel.TranType = “PUR-UKN” then raise an exception and say that this isn’t allowed… I know this is already there within the standard BPM but if you duplicate the PO with this issue (part qty = yes and Buy for = Other) it won’t popup unless you change something on the line/release level. I’m trying to make it so it also pops up on a header level… That way if a user duplicates a PO with this issue it will tell them right away to change it.

Hopefully that makes sense - this is a rushed comment :slight_smile:

What you’re asking should be possible. Just do two LINQ statements and have each one change a variable from false to true if the condition is met, then return the two conditions ANDed together.

bool condition1 = false;
bool condition2 = false;

foreach(var POHedr in ttPOHeader)
{
	var PODtl = (from pl in Db.PODetail where pl.Company == POHedr.Company && pl.PONum == POHedr.PONum && pl.PromiseDate == true select pl);
    if(!condition1)
        condition1 = (PODtl.Count() > 0)
	
}

that should get you started