Need to set the Assigned to value from another table assigned to field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 03:48 AM
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.
var ritmGR = new GlideRecord('cmdb_ci_computer');
if (ritmGR.get(current.variables.serial_number_all.toString())) {
ritmGR.query();
while (ritmGR.next()) { // loop through all records found
var someData1 = ritmGR.getDisplayValue('assigned_to');
var taskGR = new GlideRecord('alm_hardware');
taskGR.addQuery('install_status', '3');
taskGR.query();
if (taskGR.next()) { // only processes the first record
gs.log("datasome" + someData1); // im able to see the value in Log.
taskGR.assigned_to = someData1; //but its not set in the field
gs.log("datasome1" + assigned_to);
taskGR.update();
}
}
Please sugget.
Thanks all.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 03:58 AM
Good day,
Sounds like you'll need to use GlideAjax to fetch the assigned to from that table. Here are some helpful guides that should get you there!
GlideAjax | ServiceNow Developers
GlideAjax Example Cheat Sheet (UPDATED) - ServiceNow Community
Please mark this has the solution if it helped!
Kind regards,
Brad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 04:06 AM - edited 01-31-2024 04:16 AM
Hello @varma2
Can you try below code :
/* 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');
/* 2.1 Glide record on Hardware table & update assigned to */
var taskGR = new GlideRecord('alm_hardware');
taskGR.addEncodedQuery('ci='+ritmGR.getValue('sys_id') + 'install_status=3'); //here 'ci' reference needs to be given
taskGR.query();
if (taskGR.next()) {
taskGR.setValue('assigned_to', assignedTo );
taskGR.update();
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 04:48 AM
I have implemented your solution, But its not set the Assigned to value.
Please suggest,
Thanks,
Varma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 06:58 AM
I have implimented the updated code but its not setting the field and logs also im not able to see the value
var taskGR = new GlideRecord('alm_hardware');
taskGR.addEncodedQuery('ci='+ritmGR.getValue('sys_id') + 'install_status=3'); //here 'ci' reference needs to be given
taskGR.query();
if (taskGR.next()) {
gs.log("datasomenew1" + assignedTo);
Please suggest.
Thanks
