How to catch Error Message from crm scripts

lock
push_pin
done
Beantwoord
1

Hi,

I have implemented Logic for Sales in a long crm scripts, By Running the Logic it posts me Error Message: the entered number is not a valid number:

This Error Message was not defined by me in scripts. It comes then next Message with "OK to create order in SAP", this is my Message for positive Confirmation, that means the Logic go on runing after that Error Message.

Could someone tell me how could I catch this Error Message in crm scripts?

 

Thanks a lot!

17 okt 2024 | 01:27 p.m.

Alles Antwoorden (1)

Hello Jianchun, 

We always recommend developers use try/catch when writing code, and you can elevate your developer experience by adding the logging helper-method to produce logs that are easier to navigate through.

Example usage:

#setLanguageLevel 4;
#include "lib-log";  //This is the log-helper-method-library, but you can include this in your code directly if you want

String mainMethod(){
   return "foo";
}

try {
  String bar = mainMethod();
}
catch {
  printLine("Exception caught: " + error);
  printLine("...at " + errorLocation);
  log(406, 5, "Exception caught: " + error, "...at " + errorLocation);   // Uses the logger-method from the include
}


The try/catch will mean your code will no longer crash, and you can catch the error and/or even implement notifications. 
I also recommend you look at the option to activate trace on your script, but check the box "Only save if there is an unhandled exception" and use `forceSaveTrace(true)` in your catch-block.

Have a SUPER day!

//Eivind

29 okt 2024 | 07:44 a.m.

Reply toevoegen