Stopping a BPM

I am using a method directive (pre-processing) on LaborSubmit. I want to make the user scan the part number to verify. Easy peasy so far BUT…

What’s the best\proper way to halt the submission in the BPM? I thought I’d be tricky and place Terminate on Error and then do something stupid like divide by 0 but something tells me there’s a more sound approach.

Throw an exception

throw new Ice.BLException("Error: Part is not associated to this Customer.");
3 Likes

Thanks Jose!

Works great except I get stuck in a loop.

Exception throws then the T&E screen pops back up retrieving data and the BPM data form shows again.

It continues to loop until I enter proper part number - at least it’s failing in a safe condition :grimacing:

I’m thinking maybe the submit on save function might be driving this but I kinda want that feature.

What method did you hang this off of?

SubmitForApproval (pre)

The BO is just to pull JobHead so I can get part to confirm

Invoke Method… what are you invoking?

The code (where Char01 is PN field from BPM Data Form):

if(callContextBpmData.Character01.ToUpper() != JobResult.JobHead.FirstOrDefault().PartNum.ToUpper())
{
   throw new Ice.BLException("Error: Part does not match this Job!");
   return;
}

I realize the return is both unneeded and unreached... it just makes me feel better

un-related, but that’s a very heavy call just to get JobHead, write a linq query to get it instead of invoking a BO.
Either way I would move my check somewhere else, this call may not be one you can successfully halt. What gets called after this ? or before in the trace?

On failed confirmation:
SubmitForApproval is just recalled

I attempted to move the BPM to Labor.Update but I have to figure out how to get it call only in certain instances. It’s currently being called even when a new record is created.

Duly noted on using LINQ vs the BO, thanks!

Erp.Proxy.BO.LaborImpl.Update is called after

I can confirm that if I disable SUBMIT ON SAVE, the loop issue goes away

Seems like when I use LINQ, the BPM no longer likes my exception:

BPM runtime caught an unexpected exception of ‘NotSupportedException’ type.
See more info in the Inner Exception section of Exception Details

What does your LINQ look like (your whole code rather)

Wait one…stuck in a loop lol

String PART;
var part = (from jobs in Db.JobHead
                           where jobs.JobNum == ttLaborDtl.FirstOrDefault().JobNum
                           select jobs.PartNum);
{

  if(callContextBpmData.Character01.ToUpper() != part.FirstOrDefault().ToUpper())
  {
	throw new Ice.BLException("Error: Part does not match this Job!");
  }
}

It’s the FirstOrDefault() causing the error, but I don’t know why.

var part = (from jobs in Db.JobHead
                           where (string)jobs.JobNum == (string)ttLaborDtl.FirstOrDefault().JobNum
                           select jobs.PartNum).FirstOrDefault();

You can’t do firstOrdefault inside the LINQ, just use a join

?

I just need the first result of the linq. Presumably there should be one and only one, but in the event of no result I want it to fail gracefully.

The result of a linq is an iqueryable right? Why can’t I FirstOrDefault()?

the grab the first one outside the query assign it to a variable and then use it.

Hold my hand Jose. Give me an example… everytime I try to access a member of that resultset, I get the same exception!

lol have you been drinking already…