We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Auto populate Assigned vendors based on assignment group in work order task FSM

Not applicable

Hi all,

I want to auto - populate the 'assigned vendor' field  based on selection of assignment group of work order task.

Assigned vendors( assigned_vendors) - reference qualifier: javascript:'sys_idIN' + current.assignment_group.vendors.

 using on change script but it's not working.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue !== '') {
        var ga = new GlideAjax('WMAssignmentAJAX');
        ga.addParam('sysparm_name', 'getVendorAssignee');
        ga.addParam('sysparm_groupId', g_form.getValue('assignment_group'));
        ga.getXMLAnswer(function(response) {
            var result = JSON.parse(response);
            //alert("defaultVendorAssignee");
            if (!isLoading && result.defaultVendorAssignee) {
                g_form.setValue('assigned_vendor', result.defaultVendorAssignee);
                g_form.setMandatory('assigned_vendor', true);

                g_form.addInfoMessage(getMessage('Assigned vendors updated'));
            }
            g_form.setDisplay('assigned_vendor', true);
            g_form.setDisplay('vendor_reference', true);

        });
    }
}
 
include:

var WMAssignmentAJAX = Class.create();
WMAssignmentAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getVendorAssignee: function() {
var assignment_group = this.getParameter('sysparm_groupId') + '';
var result = {};
var wotvendor = new GlideRecord('core_company');
wotvendor.addQuery('sys_id', assignment_group.vendors);
wotvendor.query();
while (wotvendor.next()) {
gs.log("test" + assignment_group.vendors);

result.defaultVendorAssignee = wotvendor.name + '';

}

return new JSON().encode(result);

},

assignment_group.vendors - returns null

any help is really appreciated.

 

0 REPLIES 0