how to get the display value of a sys id being used in an array

sohan_snow
Tera Contributor

Hi All,

I need to get the assignment group of a catalog task on the description. The below scripts is working except for printing the Display value of the Grouip

grpp=[];

for(i=0;i<grpp.length;i++)
{
var gr= new GlideRecord('sc_task');
gr.request_item=current.sys_id;
gr.short_description='bingo fullillment group is : ' +grpp[i].getDisplayValue();                               //   Using grpp[i].getDisplayValue();   returns undefined
gr.description='bingo - description of this RITM';
gr.assignment_group=grpp[i];
gr.insert();
}

Catalog tasks are getting created as intended

find_real_file.png

Thanks in advance

1 ACCEPTED SOLUTION

okay, seems WF is not using ArrayUtil();



try this...



function retGrpName(val){




var gr = new GlideRecord('sys_user_group');  


gr.addQuery('sys_id',val);  


gr.query();  


while (gr.next()) {


      return gr.name;


}


},



gr.request_item=current.sys_id;


current.variables.dummy   = grpp[i];


gr.short_description='bingo fullillment group is : ' + retGrpName(grpp[i]);


View solution in original post

25 REPLIES 25

Dubz
Mega Sage

Hi Sohan,



Does your sys_user_group table have a display value assigned? I don't think it does by default. Check that out or try printing + grpp[i].name instead.


sohan_snow
Tera Contributor

Hi David,



thanks it did not have the display value , I have now set it . Do you think there could be any other issue





find_real_file.png





But still the display name isn't coming, I tried with gs.log('Bravo, the group display name is :'+grpp[i].name ); and it returned the below



find_real_file.png


How have you populated your array? It must be an issue with the data in there if you're still getting undefined values coming through.


sohan_snow
Tera Contributor

I have done it via script include




Script include




getgroup:function(){
 
  var getid=[];

var gr= new GlideRecord('u_007_access');
      gr.addQuery('u_catalog_item_name',current.variables.name);
gr.query();
while(gr.next())
 
  {
    getid=gr.u_group007+','+getid;
   
  }
  var eachId1 = getid.split(',');
 
return eachId1;

},




Workflow Run Script



var grp= new access();     \\ calls the script include
var grpp=' ';
var grpp= grp.getgroup(); \\ calls the function getgroup inside script include



gs.log('Bravo, the group returned is = '+grpp.getDisplayValue());                                   \\
gs.log('Bravo, the group length is ='+grpp);



for(i=0;i<grpp.length;i++)
{
var gr= new GlideRecord('sc_task');
gr.request_item=current.sys_id;
gr.short_description='bingo fullillment group is : ' +grpp[i].getDisplayValue();
gr.description='bingo - description of this RITM';
gr.assignment_group=grpp[i];
gr.insert();
gs.log('Bravo, the group display name is :'+grpp[i].name );
}