How to pass dynamic value in gs.addErrorMessage in Business Rule

PriyaRaj
Tera Contributor

Hi, 

I am having one business rule to check the serial number entered, if the serial number already exists for another asset in the list then the insert action for the new record will abort and should display the error msg with the asset name whose serial number matches with the newly entered serial number. But I am unable to get the asset name value here in error msg. Script  is mentioned below:

 
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('alm_asset');
gr.addQuery('serial_number', current.serial_number);
gr.query();
if (gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage('Duplicate serial number found. Please enter the unique value', +current.display_name.getDisplayValue());
 }
})(current, previous);
 
Kindly suggest some ways to display the name.
1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi I can see the comma (,) after single code ('). remove that and need to use gr.display_name to retrieve existing asset name

gs.addErrorMessage('Duplicate serial number found. Please enter the unique value', +current.display_name.getDisplayValue());

to

gs.addErrorMessage('Duplicate serial number found. Please enter the unique value ' +gr.display_name);
current.setAbortAction(true);
Regards
Harish

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Your script looks okay, what table is this BR on?

Just make sure there is a field on that table called 'display_name'

-Anurag

AnveshKumar M
Tera Sage
Tera Sage

Hi @PriyaRaj 

Change the line to because the , should be before the '

gs.addErrorMessage('Duplicate serial number found. Please enter the unique value' + current.getDisplayValue('display_name'));

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

Harish KM
Kilo Patron
Kilo Patron

Hi I can see the comma (,) after single code ('). remove that and need to use gr.display_name to retrieve existing asset name

gs.addErrorMessage('Duplicate serial number found. Please enter the unique value', +current.display_name.getDisplayValue());

to

gs.addErrorMessage('Duplicate serial number found. Please enter the unique value ' +gr.display_name);
current.setAbortAction(true);
Regards
Harish

Hi Harish, 

It is working with your suggestion.

Thank You