Automatically filled

Shir Sharvit
Tera Contributor

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

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

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);
}
}
-Anurag

Tai Vu
Kilo Patron
Kilo Patron

Hi @Shir Sharvit 

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

This is not work

Hi @Shir Sharvit 

Please share what is the issue you're facing with the above script?

It totally works fine from my side.

Screenshot 2023-11-16 at 21.28.08.png

 

Screenshot 2023-11-16 at 21.29.31.png

Screenshot 2023-11-16 at 21.30.04.png

 

 

Cheers,

Tai Vu