- 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 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:00 AM - edited 01-24-2023 08:13 AM
Thanks a lot @Sagar Pagar ! The auto population works now.
A slight issue however, is that after the first auto population, the service offering now is filtered based on the business service that's auto populated (correct behavior). The problem is that if I want to select a different service offering, the value immediately disappears. Is this because of the reference qualifier or the script?
javascript:(!gs.nil(current.business_service)? 'parent='+current.business_service: '');
update: also, after the first auto population, if I want to manually select a different business service, any service offering I choose will immediately disappear as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:14 AM
Hi @JordyZ,
Try by removing the reference qualifier.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 08:31 AM
Hi @Sagar Pagar ,
I've tried removing reference qualifier but still no success. There's also an issue when I manually populate the business service (parent) first and then select the service offering (child), the value of service offering disappears immediately.