compare array value with hardcoded string

avanis
Kilo Contributor

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 ?

7 REPLIES 7

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


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


h_ctort
Giga Contributor

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";      


}


}


}