Need to populate the service offering field value on the incident form, based on the caller location

Abhilasha G T
Tera Contributor

Hi Team,

 

Need to populate the service offering field value on the incident form, based on the caller location. I want filter the Service Offering choices based on the location on the incident form and for the look up to contain not only the name of the Service Offering but its Parent TS and the TSO Location.

 

Regards,

Abhilasha G T

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhilasha G T 

please share what did you try so far and what's not working

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I have created on change client script on Incident table with  Filed Name >caller_id and Client Callable  script include.

 

Regards,

Abhilasha G T

@Abhilasha G T Could you please share the script of onChange client script and script include. Accordingly the correction in those can be suggested. 

Hi Sandeep,

Please find the Client script and Script Include that i written,

Script include.

AbhilashaGT_0-1741842452850.png

 

var ServiceOfferingUtils = Class.create();
ServiceOfferingUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   
    getServiceOffering: function() {
        var location = this.getParameter('sysparm_location');
        if (!location) {
            return ''; // Return empty if no location is provided
        }

        var soGR = new GlideRecord('service_offering');
        soGR.addQuery('location', location);
        soGR.orderBy('name');
        soGR.query();
        if (soGR.next()) {
            return soGR.sys_id.toString(); // Return the first matching Service Offering
        }
        return ''; // Return empty if no match is found
    }
});
 
Client script:
AbhilashaGT_1-1741842526391.png
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    (function executeRule(current, gForm) {
        // Get the caller's location
        gForm.getReference('caller_id', function(caller) {
            if (caller && caller.location) {
                var ga = new GlideAjax('ServiceOfferingUtils');
                ga.addParam('sysparm_name', 'getServiceOffering');
                ga.addParam('sysparm_location', caller.location);
                ga.getXMLAnswer(function(serviceOffering) {
                    if (serviceOffering) {
                        gForm.setValue('service_offering', serviceOffering);
                    } else {
                        gForm.clearValue('service_offering');
                        gForm.addErrorMessage('No matching Service Offering found for this location.');
                    }
                });
            } else {
                gForm.clearValue('service_offering');
            }
        });
    })(current, gForm);