Got a task to make BMP which rises exception when creating new SO. When so is created ShipTo address is assigned (ShipTo table contains UD checkbox which indicates if this shipto is approved), BPM has to check if chosen ShipTo contains UD checkbox value “true” if not, rise exception, this works
But SO contains releases which can have different SfipTo addresses done that like this. firstly I check if SO header ShipTo is approved(script above in picture), if it is checked then condition routing to the script in the right and should check the same in releases. All boolens then stored in 2 variables and conditions check what values are stored inside is it true or false.
And when I use this script for releases, exception rises all the time, even if ShipTo is approved or even when you make changes on any header area it says that release ship to is not approved. Any idea what I missed. Or everything is done in bad way? Allso have no idea how to deal when releases would contain more than one ShipTo since I am storing only one bool variable for releases
Couple of things don’t look through an open Db Context that can cause record locking and un-fun things. Get your ShipTos and store them in a list then loop through that list.
var shiptoes = (from x in Db.ShipToes... blah blah).ToList();
foreach(var st in shiptoes)
{
}
Also your loop can be flip flopping that boolean, you start out at true (or false) then on each loop you set it also true or false
So if the first ship to in the loop is false then your variable is false but if the second is true then your variable flips to true so you will get inconsistent results.
@josecgomez thanks for pointing to the list. "can cause record locking and un-fun" I think you mean that for getting data directly from Db I need to use With(LockHint.NoLock), yes?
Now with using list seems I get data which I need(code below). Then the thing is that if there is few shiptoes, user needs to know which release shipto contains false. I know how to do that with info message in custom code, that should sound something like that: PublishInfoMessage(st.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Grid, string.Empty, string.Empty);
But is it possible to do it with exception?
foreach(var Orel in ttOrderRel)
{
var shiptoes = (from ShipTo in Db.ShipTo.With(LockHint.NoLock) where Orel.ShipToNum == ShipTo.ShipToNum select new {ShipTo.Active_c, ShipTo.ShipToNum}).ToList();
foreach(var st in shiptoes)
{
if(st.Active_c == false)
{
throw new Ice.Common.BusinessObjectException(new Ice.Common.BusinessObjectMessage(st.ShipToNum )
{
Type = Ice.Common.BusinessObjectMessageType.Error,
});
}
}
}