Vendor management workspace

Liz Abraham
Tera Contributor

Hello,

 

I installed the Vendor Management plugin in my PDI and was playing around with the functionality when when being on an incident form, you set the state to "On Hold" and reason  to "Awaiting Vendor", it should show vendor related fields on a tab. I am currently getting the error " getReference for cmdb_ci not allowed: missing callback function as parameter". Since this is out of the box, is there a fix? below is a screenshot of the client script. any thoughts? I did not want to change anything since these are out of the box.

 

LizAbraham_0-1689781981450.png

LizAbraham_1-1689782023966.png

 

 

 

 

7 REPLIES 7

Edvin-Karalius
Tera Guru

Because this is a client script. the way you would retrieve data is by sending a request to the server, waiting for response and then once you receive the response you are executing a function to handle that answer from the server.
Now there is an error in this script:

g_form.getReference('field_name', CALLBACK_FUNCTION_HERE);


In the script you've pasted, it is missing the function as a 2nd parameter on the getReference function.

Should look something like this:

g_form.getReference('cmdb_ci', function(record){
//do something with the response record.
});


In the case shown it's totally crazy, because then it's trying to do another gliderecord on the same thing inside of the client script. for me it looks like it's just trying to get the vendor  from the ci and set the src_vendor on your current form.
here is how this script should look like:

g_form.getReference('cmdb_ci', function(record){
  g_form.setValue('scr_vendor', record.vendor);
});


Mark as helpful if this helped you 🙂

Thank you for your response. There is something up with this script. I commented some of the code to see if it even shows the vendor fields on the incident form and doesn't seem to do that to begin with. I am not sure if I am missing something and this is very possible since I am new to ServiceNow.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading)
        return;
 
    // Need to get the form value, in case it changes but then changes back to value in database (oldValue is always DB value)
    var incidentState = JSON.parse(g_scratchpad.incidentState);
    var state = g_form.getValue("state");
 
    var AWAITING_FOR_VENDOR = "4";
 
    // If this is awaiting vendor now, show vendor fields
    if (state == incidentState.ON_HOLD && newValue == AWAITING_FOR_VENDOR) {
        showFormFields(true);
        // If no vendor is set, and CI is set, try to get vendor from CI
        if ((g_form.getValue('scr_vendor') == '') && (g_form.getValue('cmdb_ci') != '')) {
var venGr = new GlideRecord('cmdb_ci');
venGr.addQuery('name', g_form.getDisplayBox('cmdb_ci').value);
venGr.query(setVendor);
g_form.addInfoMessage(venGr.state);
        } else if (g_form.hasField('scr_vendor_ticket') && g_form.getValue('scr_vendor_ticket') == '') {
            g_form.clearValue('scr_vendor');
            showFormFields(false);
        }
    }
}
 
function setVendor(venGr) {
    if(venGr.hasNext()){
g_form.setValue('scr_vendor_ticket',venGr.vendor);
}
 
}
 
 
// function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//     if (isLoading) {
//         return;
//     }
 
//     var incidentState = JSON.parse(g_scratchpad.venGr.aincidentState);
//     var state = g_form.getValue("state");
 
//     var AWAITING_FOR_VENDOR = "4";
 
//     // If this is awaiting vendor now, show vendor fields
//     if (state == incidentState.ON_HOLD && newValue == AWAITING_FOR_VENDOR) {
//         showFormFields(true);
//         // If no vendor is set, and CI is set, try to get vendor from CI
//         if ((g_form.getValue('scr_vendor') == '') && (g_form.getValue('cmdb_ci') != '')) {
//             var record = g_form.getReference('cmdb_ci',setVendor);
//          }
//     }
 
//     // If this is no longer awaiting vendor, AND vendor not set, hide vendor fields.
//     else if (g_form.hasField('scr_vendor_ticket') && g_form.getValue('scr_vendor_ticket') == '') {
//         g_form.clearValue('scr_vendor');
//         showFormFields(false);
//     }
// }
// function setVendor(record) {
//     var grCI = new GlideRecord('cmdb_ci');
// grCI.addQuery('manufacturer','Apple');
// grCI.query();
//     if (grCI.hasNext())
//         g_form.setValue('scr_vendor', grCI.vendor);
 
// }
 
function showFormFields(show) {
    ScriptLoader.getScripts('sn_service_credits.ServiceCreditsUtil.jsdbx', function() {
        showVendorSectionFields(show);
    });
}
 
I am getting error onChange script error: TypeError: GlideRecord is not a constructor function () { [native code] } error.
 
 

Liz Abraham
Tera Contributor

I am still not able to get the vendor information from the cmdb_ci table because it gives me onChange script error: TypeError: GlideRecord is not a constructor function () { [native code] } error.