Server script is not working properly

chandan86patra
Tera Contributor

Hi All,

 

We are receiving multiple sys_id from the recordsIds but the code is not working properly 

   var recordIds = input.controller;
gs.addInfoMessage('test'+recordIds);
    var tag=recordIds.forEach(getTags);
// gs.addInfoMessage(tag);
}
 
function getTags(recordId) {
 
    var grInt = new GlideRecord('interaction');
    grInt.addQuery('sys_id', recordId);
    grInt.query();
 
    while (grInt.next()) {
 
        var grshort_description = grInt.short_description;
        var grReason = new GlideRecord('wu_m2m_location_queue_reason');
        grReason.addQuery('wu_reason.reason', grshort_description);
        grReason.query();
 
        if (grReason.next()) {
 
            var grLabel = new GlideRecord('label_entry');
            grLabel.addQuery('table_key', grReason.sys_id);
            grLabel.query();
 
            if (grLabel.next()) {
 
                var grTag = grLabel.label.getDisplayValue();
gs.addInfoMessage('test_123'+grTag);
return grTag;
         }
 
        }
    }

 

1 ACCEPTED SOLUTION

@chandan86patra 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@chandan86patra 

is this an array? if yes then do this

   var recordIds = input.controller;
   gs.addInfoMessage('test' + recordIds);
   for (var i in recordIds) {
       var tag = getTags(recordIds[i]);
       gs.addInfoMessage(tag);
   }


   function getTags(recordId) {

       var grInt = new GlideRecord('interaction');
       grInt.addQuery('sys_id', recordId);
       grInt.query();

       while (grInt.next()) {

           var grshort_description = grInt.short_description;
           var grReason = new GlideRecord('wu_m2m_location_queue_reason');
           grReason.addQuery('wu_reason.reason', grshort_description);
           grReason.query();

           if (grReason.next()) {

               var grLabel = new GlideRecord('label_entry');
               grLabel.addQuery('table_key', grReason.sys_id);
               grLabel.query();

               if (grLabel.next()) {

                   var grTag = grLabel.label.getDisplayValue();
                   gs.addInfoMessage('test_123' + grTag);
                   return grTag;
               }

           }
       }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@chandan86patra 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader