- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 10:05 AM
Hi,
I have an onChange client script + script include running that, on the incident form, the business service field (parent) gets auto populated based on the service offering field (child), before saving the form. The auto population part works, but there are issues.
Scenario 1: if you manually populate the business service first and then manually select the service offering, the value of the service offering shows for a millisecond and then immediately disappears
Scenario 2: you manually populate the service offering, this auto populates the business service (correct behavior), but when you try to select another service offering (within the same business service), the service offering value also immediately disappears
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.service_offering);
}
}
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'
});
Is there something wrong with the scripts?
Thanks,
Jordy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 08:57 AM
Since you're running the onChange on the service offering field you don't need to get the value...it's already in newValue. sc= newValue will also work. You're setting the Business Service field in this script so look for an onChange script or UI Policy that looks at or sets the Business Service field. I don't believe the reference qualifier will affect setting the value directly.
In your script include you can just return the sys_id like this.
var parentSys = gServOffering.getValue('parent');
return parentSys;
Or just
return gServOffering.getValue('parent');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 08:57 AM
Since you're running the onChange on the service offering field you don't need to get the value...it's already in newValue. sc= newValue will also work. You're setting the Business Service field in this script so look for an onChange script or UI Policy that looks at or sets the Business Service field. I don't believe the reference qualifier will affect setting the value directly.
In your script include you can just return the sys_id like this.
var parentSys = gServOffering.getValue('parent');
return parentSys;
Or just
return gServOffering.getValue('parent');