issue with script include scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 03:41 AM
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.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:16 AM
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(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 04:27 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 09:29 PM
Hi Brad,
This is not working even we add the conditions.