- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 10:23 AM
I have a need to populate a field (target) on the incident form based on the value of another field (source) also on the incident form. The source field is the configuration item field. If the configuration item field is an asset then the target field will automatically populate with the asset tag of that asset. I'm horrible at scripting and hoping someone can provide some assistance.
Thanks!
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 10:55 AM
Hello @JamesT-1 ,
You can write an on change client script on field select as Configuration item,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
// g_form.addInfoMessage(newValue);
var cmdbCI = g_form.getReference('cmdb_ci', assetTag);
function assetTag(cmdbCI) {
// **********Change the field 'u_ci_asset_tag' with name of custom field (target field)
g_form.setValue('u_ci_asset_tag',cmdbCI.asset_tag);
}
}
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 10:55 AM
Hello @JamesT-1 ,
You can write an on change client script on field select as Configuration item,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
// g_form.addInfoMessage(newValue);
var cmdbCI = g_form.getReference('cmdb_ci', assetTag);
function assetTag(cmdbCI) {
// **********Change the field 'u_ci_asset_tag' with name of custom field (target field)
g_form.setValue('u_ci_asset_tag',cmdbCI.asset_tag);
}
}
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 11:07 AM
Thanks Najmuddin,
That actually worked! So, I'm assuming I'd need to run a fixscript to populate pre-existing incidents. Any idea on what that fixscript would look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 11:16 AM
Hello @JamesT-1 ,
var grIncident = new GlideRecord('incident');
grIncident.query();
while(grIncident.next()){
// ***** change u_ci_asset_tag with your target field
gr.u_ci_asset_tag = gr.cmdb_ci.asset_tag;
gr.setWorkflow(false);
gr.update();
}
Also, to learn scripting you can enroll in Scripting in ServiceNow Fundamentals On demand course.
It helps you to understand scripting in a simpler way.
LINK:
https://learning.servicenow.com/lxp/en/now-platform/scripting-in-servicenow-fundamentals-on-demand-w...
If the above information helps you, Please mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2025 11:02 AM
I am assuming your target field is of string type then you can configure in field's dictionary itself, but it will show up once form is saved after selecting the CI.
