issue with script include scripting

AnandKumar1
Tera Expert

Hi Team,

My requirement is on the incident in related list vendor whenever the vendor is selected as 1 value then it should update 2 values.

 

1. when Vendor value is ABC then my logic should work like to "query the related incident number and from that it should take the affected CI. Then to fetch the related values (Model number and serial number). I have tried with below scripts but it's not working. 

 

CLIENT SCRIPT : (onchange) of field vendor

if(newValue == 'eddfbce1dbb3b6c43cc3fbc61d9619be'){

var gb = new GlideAjax('global.getCISerialNo') ;
gb.addParam('sysparm_name', 'getmodel');
gb.addParam('sysparm_ci',g_form.getReference('u_parent_incident').cmdb_ci);
gb.getXMLWait();
//alert(ga.getAnswer());

//g_form.setValue('u_model_number',gb.getAnswer());
function callBack(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var val = JSON.parse(answer);
g_form.setValue('u_model_number', val[0]);
g_form.setValue('u_serial_number', val[1]);

}

=========================================================================

SCRIPT INCLUDE:

getmodel :function()
{
var ar = [];
var CI = this.getParameter('sysparm_ci');
var CISr = new GlideRecord('cmdb_ci');
CISr.addQuery('sys_id',CI);
CISr.query();
if(CISr.next())
{
ar.push(CISr.getValue('model_id.getDisplayValue'));
ar.push(CISr.getValue('serial_number'));
}
return JSON.stringify(ar);
},

But i am receiving null values on the fields.

 

AnandKumar1_0-1673523672435.png

 

Thanks.

 

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

As with troubleshooting any script, add some log lines, especially in the SI, to make sure it's running, confirm the CI value passed in from the client, and see what values, if any, are pushed to the array.  In this case you only have an array with 2 values (if the GR and your getValue/push lines are working), so there's no JSON to stringify.  Try just 

return ar.join(',');

The join is implied, but always best to be clear.  Then in the CS callback

var val = answer.split(',');

 

Hi Brad,

Thanks for your quick response.  i have added alert(answer); in the client script and when the vendor details placed i am getting alert as null.

 

Thanks.

Right, so you have to go back to the Script Include and see why it is returning null to the client.  Did you make any of the changes that I suggested?

Hi Brad,

This is not working even we add the conditions.