Regarding population of location field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
59m ago
Hello,
I am having requirement to auto populate location field when configuration item (CI) is selected on incident form. for both the fields data is taking from cmdb_ci table. i have written client on change script and script include but its not giving results. Any suggestions on this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
36m ago
Hi @rutujalande
Try this:
- The Script Include
- Name: CIUtils
- Client callable: Checked
var CIUtils = Class.create();
CIUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCILocation: function() {
var ciSysId = this.getParameter('sysparm_ci_id');
var locationId = '';
if (ciSysId) {
var grCI = new GlideRecord('cmdb_ci');
if (grCI.get(ciSysId)) {
locationId = grCI.getValue('location') || '';
}
}
return locationId;
},
type: 'CIUtils'
});
- Create onChange Client Script
- Name: Populate Location from CI
- Table: Incident
- Field name: Configuration item [cmdb_ci]
- Type: onChange
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if (newValue === '') {
g_form.clearValue('location');
}
return;
}
var ga = new GlideAjax('CIUtils');
ga.addParam('sysparm_name', 'getCILocation');
ga.addParam('sysparm_ci_id', newValue);
if (response) {
g_form.setValue('location', response); // Sets the actual location reference field
} else {
g_form.clearValue('location');
}
});
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
35m ago
so what debugging did you do?
script include is client callable?
both script include and client scripts are in same scope?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader