compare array value with hardcoded string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 09:24 AM
Below is the code getting values from catalog item variable and converting it to array.
variable type is list collector having values for Role.
I need to add something to description at the end for a particular Role, but unable to find way to do it.
var Roles = current.variables.w_role+"";
var roles = Roles.split(',');
for(var i=0;i< roles.length;i++)
{
var wRoleTable = new GlideRecord("tablename");
wRoleTable.addQuery("sys_id",roles[i]);
wRoleTable.query();
if(wRoleTable.next())
{
task.description += (i+1)+" : "+wRoleTable.u_usage_role+"\n";
}
}
I was trying this code but it doesn;t seem to work.
if(roles.indexOf("Project Manager") >= 0)
{
task.description += "Please add this user to the XXX group."+ "\n";
}
Any suggestions to try here please ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 09:29 AM
Hi Avani,
Can you try replacing roles with Roles (R in caps)
if(Roles.indexOf("Project Manager") >= 0)
{
task.description += "Please add this user to the XXX group."+ "\n";
}
Thank You
Please Hit Like, Helpful or Correct depending on the impact of response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 10:40 AM
I tried this,but doesn't seem to work.. 😞
var Roles = current.variables.w_role+"";
var roles = Roles.split(',');
for(var i=0;i< roles.length;i++)
{
var wRoleTable = new GlideRecord("tablename");
wRoleTable.addQuery("sys_id",roles[i]);
wRoleTable.query();
if(wRoleTable.next())
{
task.description += (i+1)+" : "+wRoleTable.u_usage_role+"\n";
}
}
if(Roles.indexOf("Project Manager") >= 0)
{
task.description += "Please add this user to the XXX group."+ "\n";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 10:43 AM
In the line var Roles = current.variables.w_role+"";
Are you sure Roles are returning proper role names or is it the Sys_id of roles? Can you try logging the value of Roles variable?
Thank You
Please Hit Like, Helpful or Correct depending on the impact of response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 10:07 PM
Hi,
I guess it is returning the sys ID as in below gliderecord query we are comparing it with sys ID.
but how to convert it into value, i tried it with ".value" but it doesnt work...