Array in client script Help!!!

malu
Tera Contributor

Hi All, I have a assignment group list array in client script I want NOT to show a field if incident assignment group contains one of this group.

var arrayList = ['test1','test2','test3'];

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Malu,



What you can do is get the group name present on incident form and search it in this array


var incidentGroupName = g_form.getValue('assignment_group');


query group table with this sys_id and then get name in variable b


var arrayList = ['test1','test2','test3'];


var arrayUtil = new ArrayUtil();


var isContained = arrayUtil.contains(arrayList, b);



if(isContained){


// found


// do your stuff i.e. show, hide etc


}


else{


// not found


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Deepa Srivastav
Kilo Sage

Can be done like below too:



var grpNames=['test1','test2','test3'];


  var hasGrp=0;


var chkAssignGrp=g_form.getDisplayBox('assignment_group').value;


  for(var i=0;i<grpNames.length;i++)


  {


  if(grpNames[i]==chkAssignGrp)


  hasGrp='1';


  }


if (hasGrp=='1')


  {//do your stuff


}



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy


Deepak Ingale1
Mega Sage

Hi Malu,



You can write down below code



var currentGroup = g_form.getValue('assignment_group').toString();


var groupList = ['group1id','group2id'];



groupString = groupList.join(',');



if (groupString.indexOf(currentGroup) > -1) { // current group exits in group list


  do this;


  return;


}


do that;


return;


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Malu,



Did you try the solution proposed by me in the comment?


you can let me know if any issue.


If already resolved you can mark the answer as correct and hit like and helpful. Thanks in advance.



Regards


Ankur


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