Need to set the Assigned to value from another table assigned to field.

varma2
Mega Sage

Hi All,

 

I have a requirement i need to set the Assigned_to field value on alm_hardware from cmdb_ci_computer assigned_to.

 

we have a catalog item in the variable name called ( serial_number_all ) which is having name of asset. that asset name populated from cmdb_ci_computer in that that table we have( assigned to ) That value we need to populate to alm_hardware table assigned to.

below is the script in logs I'm able to see the user value  but its not set in the assigned to field..

varma2_0-1706799997818.png

But its not set in assigned to field, Please suggest

 

  
 
/* 1. Get Serial number variable value  */
var serialNum = current.variables.serial_number_all;
 
/* 2. Glide record on cmdb_ci_computer*/
var ritmGR = new GlideRecord('cmdb_ci_computer');
ritmGR.addEncodedQuery('sys_idIN'+ serialNum);
ritmGR.query();
 
while (ritmGR.next()) { 
   
var assignedTo = ritmGR.getValue('assigned_to');
gs.log("datasomenew" + ritmGR.assigned_to);        
 
/* 2.1 Glide record on Hardware table & update assigned to */
  
 var gr=new GlideRecord('alm_hardware');
gr.addQuery('install_status', 3);
gr.query();
 if(gr.next()){
gr.setValue('assigned_to', assignedTo );
 gr.update();
  gs.log("datasomenew4" + assigned_to);  
}
}
  
Thanks,
4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @varma2 

 

Probably, the filter query which you have applied on the table alm_hardware (gr.addQuery('install_status', 3);) is not working. Request you to check the query and retry.

 

Also, which record in alm_hardware table you are trying to update ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi @Amit Verma ,

 

The query is working after the log we can able to see the value but we are unble to set that to field.

Please suggest

 

Thanks,

 

/* 2.1 Glide record on Hardware table & update assigned to */

 

Can you please elaborate on the query you want to apply on the alm_hardware table ?


Please mark this response as correct and helpful if it assisted you with your question.

Pranesh072
Mega Sage
Mega Sage

On alm_hardware you are using only this query 'install_status' == 3. Probably all the values are getting updated on a single record. 

 

/* 1. Get Serial number variable value  */
var serialNum = current.variables.serial_number_all;
 
/* 2. Glide record on cmdb_ci_computer*/
var ritmGR = new GlideRecord('cmdb_ci_computer');
ritmGR.addEncodedQuery('sys_idIN'+ serialNum);
ritmGR.query();
 
while (ritmGR.next()) { 
   
var assignedTo = ritmGR.getValue('assigned_to');
gs.log("datasomenew" + ritmGR.assigned_to);        
 
/* 2.1 Glide record on Hardware table & update assigned to */
  
 var gr=new GlideRecord('alm_hardware');
gr.addQuery('install_status', 3);
gr.query();
 if(gr.next()){
gr.setValue('assigned_to', assignedTo );
 gr.update();
  gs.log("datasomenew4" + assignedTo );  
}
}