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-11-2017 01:35 AM
You are already validating the roles in the for loop
var Roles = current.variables.w_role+"";
var roles = Roles.split(',');
for(var i=0;i< roles.length;i++){
var wRoleTable = new GlideRecord("sys_user_role");
wRoleTable.addQuery("sys_id",roles[i]);
wRoleTable.query();
if(wRoleTable.next()){
task.description += (i+1)+" : "+wRoleTable.u_usage_role+"\n";
if(wRoleTable.name == 'project_manager'){ //Replace your role name here from Roles table
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-15-2017 03:02 AM
Hello Avani,
If I have answered your query, request you to mark my response as correct answer and close the thread.
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:51 AM
Hi, use this code an an example:
var roles = current.varibales.w_role.split(',');
for(var i=0;i< roles.length;i++)
{
var wRoleTable = new GlideRecord('sys_user_role');
wRoleTable.addQuery('sys_id',roles[i]);
wRoleTable.query();
if(wRoleTable.next()){
if(wRoleTable.name == 'project_manager'){ //Compares the current record with the role you defined
task.description += (i+1)+" : "+Add your description+"\n";
}
}
}