Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get all RITMs(Order Guide) description in Request Description field

Rakesh11
Tera Contributor

I have requirement where I need to populate all the RITMs  description in Request Description field
For example: If 3 RITMs are there for 1 request. Then description of all the Ritms should be populated in request description.

 

Business Rule :

table :Sc_request

Condition: After Insert

 

(function executeRule(current, previous /*null when async*/ ) {
  var dateTime = new GlideDateTime();
    dateTime.addSeconds(5);
     gs.eventQueueScheduled('event_name', current, '', '', dateTime);
})(current, previous);
 

Script Action:

var req = new GlideRecord('sc_req_item');
req.addQuery('request', current.sys_id);
req.query();
 
while (req.next()) {
req.getRowCount();
if(req.getRowCount() == 1){
current.description = req.number + ": " + req.description;
}
else{
current.description = "Multiple RITMs are as follows: " + '\n' + req.number;
}
}
current.update();
 
This is not working as expected. Please help
1 REPLY 1

Amit Verma
Kilo Patron
Kilo Patron

Hi @Rakesh11 

 

You can achieve this via a before insert Business rule on sc_request table. Below are the snips and code for your reference :

 

image.png

 

(function executeRule(current, previous /*null when async*/) {
var reqDescription = "Multiple RITMs are as follows: " + '\n';
var req = new GlideRecord('sc_req_item');
req.addQuery('request', current.sys_id);
req.query();
 
while (req.next()) {
req.getRowCount();
if(req.getRowCount() == 1){
reqDescription += req.number + ':' + req.description;
}
else{
	reqDescription += req.number + ':' + req.description + '\n' ;
}
}
current.description = reqDescription ;

})(current, previous);

 

Output :

 

AmitVerma_1-1703142759585.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.