Automatically filled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 05:22 AM
Hi.
In the incident form,
if the "service" field is empty, should be filled in automatically when the "service offer" field is filled. If the "service" field is full - do not update it.
The value to be filled in the "service" field is the value in the "service offer" parent field (which is a reference to the record).
The record that is filled has a field called "parent" - this is the value that will enter the "service" field.
I need to solve this by using Client script include (GlideAjax).
In the past I have solved this by using getreference() with this code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var serv_offering = g_form.getReference('service_offering', setService);
}
function setService(serv_offering) {
var businessServiceValue = g_form.getValue('business_service');
if (!businessServiceValue) {
g_form.setValue('business_service', serv_offering.parent);
}
}
Thanks.Shir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 05:28 AM
HI,
If i understand correct the only change you want is that of the service field is already filled it should not be updated again or overridden, if so then use this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getValue('business_service') =='')
{
var serv_offering = g_form.getReference('service_offering', setService);
}
}
function setService(serv_offering) {
var businessServiceValue = g_form.getValue('business_service');
if (!businessServiceValue) {
g_form.setValue('business_service', serv_offering.parent);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 05:32 AM
There you go with GlideAjax.
#Script Include
var CLIncidentUtilsAJAX = Class.create();
CLIncidentUtilsAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getService: function(){
var offering_id = this.getParameter('sysparm_offering_id');
var grOffering = new GlideRecord('service_offering');
if(grOffering.get(offering_id)){
return grOffering.getValue('parent');
}
return '';
},
type: 'CLIncidentUtilsAJAX'
});
#Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var businessServiceValue = g_form.getValue('business_service');
if (!businessServiceValue) {
var ga = new GlideAjax('global.CLIncidentUtilsAJAX');
ga.addParam('sysparm_name', 'getService');
ga.addParam('sysparm_offering_id', newValue);
ga.getXMLAnswer(function(response) {
g_form.setValue('business_service', response);
});
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 06:15 AM
This is not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 06:30 AM
Please share what is the issue you're facing with the above script?
It totally works fine from my side.
 
Cheers,
Tai Vu