- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023
07:39 AM
- last edited on
09-16-2023
01:43 AM
by
ServiceNow
Hi,
On the incident form I'd like to have business service field (parent) auto populated based on service offering field (child), before saving the form.
I have found a post that had a similar query:
| https://www.servicenow.com/community/itsm-forum/filter-the-service-offering-field-based-on-parent-se... |
I have tried to tweak the client script and script include to fit my specific need, but it doesn't work. What happens now is that the moment I try to manually populate the service offering field, the value immediately disappears. The most probable cause of the scripts failing is because I'm putting the wrong field/column names in the wrong places of the code.
I'd appreciate it if someone could look at the code. I have also attached screenshots that might help.
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sc = g_form.getValue('service_offering');
var ga = new GlideAjax('dvtbsautopop');
ga.addParam('sysparm_name', 'getServDetails');
ga.addParam('sysparm_servId', g_form.getValue('service_offering'));
ga.getXMLAnswer(getResponse);
function getResponse(response) {
var res = JSON.parse(response);
g_form.setValue('business_service', res.business_service);
}
}
Script include
var dvtbsautopop= Class.create();
dvtbsautopop.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServDetails: function() {
//gs.addInfoMessage('script include triggered');
var servId = this.getParameter('sysparm_servId');
//gs.addInfoMessage('service scr--' + servId);
obj = {};
var gServOffering = new GlideRecord('service_offering');
if (gServOffering.get(servId)) {
obj.service_offering = gServOffering.getValue('parent');
}
//gs.addInfoMessage(obj+JSON.stringify(obj));
return JSON.stringify(obj);
},
type: 'dvtbsautopop'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 07:45 AM
Hi @JordyZ,
Update client scripts as -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sc = g_form.getValue('service_offering');
var ga = new GlideAjax('dvtbsautopop');
ga.addParam('sysparm_name', 'getServDetails');
ga.addParam('sysparm_servId', g_form.getValue('service_offering'));
ga.getXMLAnswer(getResponse);
function getResponse(response) {
var res = JSON.parse(response);
g_form.setValue('business_service', res.service_offering);
}
}
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:35 AM
Hi @JordyZ,
Is there any other client scripts working on same field/column?
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:38 AM - edited 01-24-2023 08:49 AM
Hi @Sagar Pagar,
No, only reference qualifiers and your script.
edit: This is the dictionary override of business service, I don't know if it helps.
