Need Help with Script Include

Nilanjan1
Mega Sage

Dear Experts, 

 

I am trying to populate the Business Service Offering through Business Service (I know it should be other way round) I have created a script include and the client callable script somehow I am unable to get the data in. Can someone help. If someone can guide I will be really greatful. 

Script include

var GetRelatedServiceOfferings = Class.create();
GetRelatedServiceOfferings.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getOfferings: function() {
        var serviceId = this.getParameter('sysparm_service_sys_id');
        if (!serviceId) return JSON.stringify([]);

        var relTypeGR = new GlideRecord('cmdb_rel_type');
        relTypeGR.addQuery('parent_descriptor', 'Depends on');
        relTypeGR.addQuery('child_descriptor', 'Used by');
        relTypeGR.query();
        if (!relTypeGR.next()) return JSON.stringify([]);
        var relTypeSysId = relTypeGR.getUniqueValue();
        var result = [];
        var relGR = new GlideRecord('cmdb_rel_ci');
        relGR.addQuery('type', relTypeSysId);
        relGR.addQuery('parent', serviceId);
        relGR.query();

        while (relGR.next()) {
            var offering = relGR.child.getRefRecord();
            if (offering && offering.getTableName() === 'service_offering') {
                result.push({
                    sys_id: offering.getUniqueValue(),
                    name: offering.getDisplayValue()
                });
            }
        }

        return JSON.stringify(result);
    }
});

 

 Client script

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearOptions('service_offering');
        return;
    }

    var ga = new GlideAjax('GetRelatedServiceOfferings');
    ga.addParam('sysparm_name', 'getOfferings');
    ga.addParam('sysparm_service_sys_id', newValue);
    ga.getXMLAnswer(function(response) {
        var offerings = JSON.parse(response);
        g_form.clearOptions('service_offering');
        g_form.addOption('service_offering', '', '-- None --');
        offerings.forEach(function(offering) {
            g_form.addOption('service_offering', offering.sys_id, offering.name);
        });
    });
}

  

4 REPLIES 4

Daxin
Tera Expert

if you are following CSDM, the business service and service offerings are related through reference. So you could query the service offering table which has reference of business service.

The service offering are related to the Services with a relationship type and these fields are references in a service catalog form, hence I am looking to ensure that the information gets populated when someone selects an offering or services. 

 

Also the auto populate feature is not helpful here in the ref fields is also not able to pull the records. 

Hristo Ivanov
Kilo Sage

not sure if you didn't copy it but the script include needs to have "type: 'GetRelatedServiceOfferings' " at the end

Ankur Bawiskar
Tera Patron
Tera Patron

@Nilanjan1 

so what debugging did you do?

Is the script include client callable?

Is some log coming in script include?

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