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

Alikutty A
Tera Sage

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


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


  }


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


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...