Epicor Function - scope, when transaciton is saved to db, return keyword scope

I have a function with structure like below:

this.CallService<Erp.Contracts.JobEntrySvcContract>(boJobEntrySvc =>
{
    //block1
});

//block2

this.CallService<Erp.Contracts.IssueReturnSvcContract>(boIssueReturnSvc =>
{
    //block3
});

First issue / question:
if I will place a “return” statement in block1 then I was expecting to leave Function instead it leave only block1. Block2 and block3 code was executed. Is that expected?

Second issue / question:
What I need to do if I want to

  1. terminate code execution from block3
  2. transaction from block1 should be not saved in that case
  3. capture my exception/termination reason in Kinetic. I am calling my function from Kinetic Application Studio.

I was trying to throw an exception but having issue with showing nice message to user instead of stack trace and could not access my out variables.

Each of those are basically their own functions you need to return or set variables and use if statements to continue (or not )

Catch your exceptions and set a variable called Message to whatever you want the exception to be

For example all our functions always return

Success (Boolean)
Message (String)

Other result related stuff

If success is false then the message is what I want the user to see

This is exactly what I did when I discover that ‘return’ is just leaving a block instead of leaving whole EFx. I wanted to make sure I wasn’t going crazy :slight_smile:

I was doing similar thing but then I just drop using Boolean as I was checking if String (my ExMsg variable) is Empty. For communication with user I was using InfoMsg variable. Logic was following. Is ExMsg empty - not, then show it, if yes then check InfoMsg and show if not empty.

We are still on EFx level. I was already thinking about next step which is to suppress exception in UI and replace it with nice information. Not a problem in classic interface but I need to do in Application Studio. I believe I saw an option to suppress exception on rest-erp widget. Have to check it.

Thank you for your answer.