- 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-24-2023 12:16 PM
Hi, your script does not seem to set content for 'service_offering' field and based on your description I would suspect that you have other client side scripts or policy setting content of this field based on a change to 'business_service'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 02:32 PM - edited 01-24-2023 02:42 PM
Hello @Tony Chatfield1 , thanks for replying.
the only thing I have for the service offering field as far as I know is this ref qualifier:
javascript:(!gs.nil(current.business_service)? 'parent='+current.business_service: '');
Or could this have anything to do with it? It's the dictionary override of the business service field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 02:57 PM
When is that client script running? onChange of business service? It sounds like you have multiple onChange scripts or UI Policies conflicting.
You're just returning a sys_id string you don't need an object in your script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 03:07 PM - edited 01-24-2023 03:14 PM
Hi @ricker, thanks for replying.
It's onChange of service offering. I don't see any other scripts running for this field, nor any UI policy that could clash with it. Is there a way to know for sure?
The only thing I have for the service offering field as far as I know is this ref qualifier:
javascript:(!gs.nil(current.business_service)? 'parent='+current.business_service: '');
Or could this have anything to do with it? It's the dictionary override of the business service field.
What would the script look like without the object?