on ‎2021 May 19 7:03 PM
Hello Expert,
I have a long script which execute multiple transactions in happy path, I am working on error handling and want to exit from script if it certain condition , generate message and go back to the initial page of transaction. I am able to use if condition to validate condition as well as able to generate message. But when user correct the input of initial screen and hit script execution button its starting from middle of the script not the initial line.
Could you please suggest a way to come out of script once script faces a error, some thing like refresh screen and start from the beginning once user hit execute.
Thanks
RD
Request clarification before answering.
Hi Ritesh,
Without the details of what you are doing, it will be hard to give you a specific answer. I'm going to make the assumption you are in the same flavor and scripting from there (i.e. you are not switching to a new flavor during your script). Anytime I need to stop my script from running I use a "return true". This will immediately stop the current script from continuing or stop the current function from continuing. I would normally do validation in the first part of my scripting after user clicks a button such as save or next, etc. If validation fails then I would do a "return true".
Here is a snippet of code I use in one of my flavors.
//--------------------------------------------------------------------------------------------------------------
//Validation
// 4) Get Order and Operation numbers
var z_wo = session.findById("wnd[0]/usr/subHEADER:SAPLCMFU:0201/ctxtCMFUD-AUFNR").text;
var z_op = session.findById("wnd[0]/usr/subHEADER:SAPLCMFU:0201/ctxtCMFUD-VORNR").text;
//5) Check that a value is entered in the order field
if(z_wo === '')
{
session.findById("wnd[0]/sbar").setMessage('Enter an Order', 'E');
session.findById("wnd[0]/usr/subHEADER:SAPLCMFU:0201/ctxtCMFUD-AUFNR").setFocus();
return true;
}
// 6) Check that a value is entered in the operations field
if(z_op === '')
{
session.findById("wnd[0]/sbar").setMessage('Enter an Operation', 'E');
session.findById("wnd[0]/usr/subHEADER:SAPLCMFU:0201/ctxtCMFUD-VORNR").setFocus();
return true;
}
// 7) Press enter to trigger SAP validatation
session.findById("wnd[0]").sendVKey(0);
// 8) Deal with any SAP messages - LOOKING FOR ERROR MESSAGE BY SAP
if(session.findById("wnd[0]/sbar").messageType == 'E')
{
session.utils.log('Error message encountered - STOP THE SCRIPT FROM FURTHER PROCESSING');
return true;
}
Hope this helps.
Thanks,
Brian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
bwills,
Sorry I was not able to explain my issue properly but you assumed it correctly and solved my problem.
A Big Thank You !!
Thanks
RD
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ritesh.dube,
You are welcome! Glad I was able to help.
Thanks,
Brian
Hi RD,
I would use multiple functions, and depending on the value returned by every function, execute the next one, otherwise, go back to the beginning. I would use variables to control the flow (store the results from each function) and act upon their values.
Regards,
Cris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
cristiano.hansen
Thanks, for each success result i do not have any issue. But when I come across a error i want to back to the inertial screen , and i am not sure how to do that .
go back to the beginning. I would use variables to control the flow (store the results from each function) and act upon their values.could you add more on it or give a example.
Thanks
RD
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi RD,
Like I mentioned, if there was an error, it would be caught in the result of a function. Then a simple if, testing for the error, would cause the script to reset all variables and calling the original transaction again (using, for example, session.callTransaction()).
Regards,
Cris
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.