- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 07:33 AM
Hi all,
Refer to the subject, I am writing an UI Macro with below code, which need to compare the CSV values, I have put the code in business rule to debug , then found the script can work (Pic 1) when user.lob only has one single value. But if user.lob has multiple values, the CONTAINS will not work, result in Pic 2.
We also tried use "IN" instead of "CONTAINS", but still no lucky. Any one know how to split the CSV values into one by one to do the comparison? We need to check if block lobs contain user lob.
Business rule for debug:
var isValid = false;
var u = gs.getUserID();
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',u);
user.query();
while(user.next())
{
gs.print("user LOB is: " + user.lob);
gs.addInfoMessage("user LOB is: " + user.lob);
var hrblock = new GlideRecord('portal');
hrblock.addQuery('sys_id', current.sys_id);
hrblock.addQuery('lob','CONTAINS', user.lob);
hrblock.query();
while(hrblock.next())
{gs.print("block LOB is: " + current.lob);
gs.addInfoMessage("block LOB is: " + current.lob);
gs.print("enter into while");
gs.addInfoMessage("enter into while");
isValid = true;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2016 08:25 AM
To recap, you check if, on the current portal record (current.sys_id) if the "lob" field contains any of the value(s) the current user record has in the lob field.
In that case, the script below should work (as well as Cory's, but I didn't try it). Give it a shot and let us know.
var isValid = false;
var u = gs.getUserID();
var user = new GlideRecord('sys_user');
if (user.get(u)){
var lob = user.getValue("lob").split(',');
var hrblock = new GlideRecord('portal');
if (hrblock.get(current.sys_id)){
var hrblockArray = hrblock.getValue("lob").split(',');
for (var i = 0; i < lob.length; i++){
for (var j = 0; j < hrblockArray.length; j++){
if (lob[i] == hrblockArray[j]) isValid = true;
}
}
}
}
Assuming it works in your case, I would make some optimizations so that if it found a match, it would exit the loop and stop executing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2016 07:00 AM
Hi Brain,
Thank you so much for your sharing as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2016 02:35 PM
Sorry, I misread part of your question before... trying to do too many things at once today.
To split the values of a CSV list into an array:
var arrLob = user.lob.toString().split(',');
Then you can work with each value arrLob[0], arrLob[1], etc., by looping with an index variable...
for(var i=0; i < arrLob.length; i++){
(do your query...)
}
-Brian
Edit: Like Cory outlined for you, but he forgot the (',') for splitting a CSV list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 03:18 AM
Hi All,
Following is the script to get the sys_ids in array.
In below script I have splitted the assignment group members in an array . Hope it will help someone!
var rolesgr2;
var arr=[];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id','put sysID of group here');
gr.query();
if(gr.next())
{
var gr1=new GlideRecord('sys_user_grmember');
gr1.addQuery('group','put sysID of group here');
gr1.query();
while(gr1.next())
{
arr.push(gr1.user.toString()); //push name in arr
}
gs.print('Members IN ARRAY2---->'+arr );
var members = [];
members=arr.toString().split(",");
gs.print('Length-'+members.length);
for (var i=0; i<members.length; i++)
{
gs.print('Member -> '+members[i]);
}
//Check the role of the members
for (var i2=0; i2<members.length; i2++)
{
rolesgr2 = new GlideRecord('sys_user_has_role');
rolesgr2.addQuery('user',members[i2]);
rolesgr2.query();
if(rolesgr2.next()) // if watchList user has role
{
gs.print('HAS ROLE Member '+rolesgr2.user.getDisplayValue()+ ' Role - '+ rolesgr2.role.getDisplayValue());
}
else
{
gs.print('HAS No ROLE Member '+rolesgr2.user.getDisplayValue()+ 'Role - '+ rolesgr2.role.getDisplayValue());
}
}
}