Writing a business rule for a catalog Item. Scripting

Ankita NA
Tera Contributor

 

I have a catalog Item VM Provisioning, for which my requirement is

Stage1: if RITM Stage is 'Request Approved' then I need to append the 'description of RITM' with +' The RITM needs further action '.

Stage1: if RITM Stage is 'Request Completed' then I need to append the 'description of RITM' with +' The RITM needs no further action '

For this I am creating a business rule and writing a script, below are screenshots. Please help me out with corrections.

The below code is working fine for a single record not able to do it for all records.

 

var newdescription;
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number','RITM3859718');
gr.query();
if (gr.next()){
if (gr.stage == 'request_approved'){
newdescription = gr.description +' '+'The RITM needs further action';
gr.setValue('description',newdescription);
gr.update();
}

else if(gr.stage == 'request_completed');{
newdescription = gr.description +' '+'The RITM needs no further action ';
gr.setValue('description',newdescription);
gr.update();
}

}

4 REPLIES 4

OlaN
Giga Sage
Giga Sage

Hi,

You should not do this in a business rule.

Instead, set the description of the RITM in Flow actions or in Workflow run scripts.

@OlaN why do you think we should not do this via BR?

To avoid having multiple sources changing the data in the RITM record.

mayank_bhardwaj
Tera Contributor

Code is working fine for a single record and not able to do it for all records because you are running it for 'RITM3859718' only

Add your code in runscript in your catalog workflow 
gr.addQuery('number','RITM3859718'); // remove this line from your code