I am unable to track assets assigned to the user

divyal09
Tera Contributor

I am unable to track assets assigned to the user. While sumitting termination form for the user all the hardware assigned to that user should be tagged in one task. I am only able to tag one hardware using workflow catalog task condition.

 

The code I added is 

var usrid = current.variables.employee_name;
var hardware = new GlideRecord('alm_hardware');
hardware.addQuery("assigned_to",usrid);
hardware.query();
var hardware_details = '';
while (hardware.next()){
    hardware_details = 'Name' + '-' + hardware.display_name + '\n';
    if(hardware_details){
           task.description = 'Please disable/remove access for ' + current.variables.employee_name.getDisplayValue() + ' terminated on ' + dt + ' from your application and where applicable, associated servers, databases and other applications for which user has access.' + '-'' '+ hardware_details;
   
}
}
1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @divyal09,

 

(Updated - I forgot to un-comment the task.description during my testing)

Use the below slightly updated script.

You needed to append to the hardware_details each for each loop and only update the task.description after this. See below:

 

 

 

 

var usrid = current.variables.employee_name;
var hardware = new GlideRecord('alm_hardware');
hardware.addQuery("assigned_to",usrid);
hardware.query();
var hardware_details = '';
while (hardware.next()){
    hardware_details += 'Name' + '-' + hardware.display_name + '\n'; // += appends for each asset within the while loop
}
    if(hardware_details){ //We only print out or update the task description once the while loop has finished
           task.description = 'Please disable/remove access for ' + current.variables.employee_name.getDisplayValue() + ' terminated on ' + dt + ' from your application and where applicable, associated servers, databases and other applications for which user has access.' + '-' + ' '+ hardware_details;

}

 

 

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

View solution in original post

3 REPLIES 3

Robbie
Kilo Patron
Kilo Patron

Hi @divyal09,

 

(Updated - I forgot to un-comment the task.description during my testing)

Use the below slightly updated script.

You needed to append to the hardware_details each for each loop and only update the task.description after this. See below:

 

 

 

 

var usrid = current.variables.employee_name;
var hardware = new GlideRecord('alm_hardware');
hardware.addQuery("assigned_to",usrid);
hardware.query();
var hardware_details = '';
while (hardware.next()){
    hardware_details += 'Name' + '-' + hardware.display_name + '\n'; // += appends for each asset within the while loop
}
    if(hardware_details){ //We only print out or update the task description once the while loop has finished
           task.description = 'Please disable/remove access for ' + current.variables.employee_name.getDisplayValue() + ' terminated on ' + dt + ' from your application and where applicable, associated servers, databases and other applications for which user has access.' + '-' + ' '+ hardware_details;

}

 

 

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

divyal09
Tera Contributor

Thank you 

No worries at all @divyal09 - Glad to help.

Happy Wednesday and happy coding ; )

 

Robbie