Auto Populate Data in multi row variable set

gautam_dhamija
Tera Contributor

i am trying to autopopulate the data in mrvs on the onchange of variable in Another mrvs but not able to do it

here is the client script

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

var poNumber = g_form.getValue('po_number');

var ga = new GlideAjax('CheckForDuplicity');
ga.addParam('sysparm_name', 'getData');
ga.addParam('po_number', poNumber);

ga.getXMLAnswer(function(response) {
alert(response);
var data = JSON.parse(response);

g_form.clearValue('line_item');

data.result.forEach(function(item) {
var newRow = g_form.addRow('line_item');
g_form.setValue('line_item.line_no', item.grn || '', newRow);
g_form.setValue('line_item.product_code', item.vendor_code || '', newRow);
g_form.setValue('line_item.sac_hsn_code', item.tds_code || '', newRow);
g_form.setValue('line_item.description', item.line_items || '', newRow);
g_form.setValue('line_item.amount', poNumber, newRow);
});
});
}

 

here is the script include:

getData: function() {
var poNumber = this.getParameter('po_number');
var result = [];
var gr = new GlideRecord('x_perii_account_0_po_line_item');
gr.addQuery('purchase_order', poNumber);
gr.query();

while (gr.next()) {
gs.addInfoMessage('working');
result.push({
row_id: gr.sys_id.toString(),
grn: gr.getValue('grn'),
vendor_code: gr.getValue('vendor_code'),
tds_code: gr.getValue('tds_code'),
line_items: gr.getValue('line_items')
});

return JSON.stringify({
success: true,
result: result
});
}
}

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

Good job adding the logs - are you getting the expected value when alerting on 'response'? If not, are you getting the 'working' info message?  If one or neither of these is happening, more logs may be necessary.  Is 'line_item' the internal name of the MRVS you are trying to populate?  Do you really want to clear the MRVS before adding a new row?  Is this script running onChange of the (po_number?) variable in a different MRVS?  Is the Script Include in the same scope as the Catalog Item / Catalog Client Script? I don't see a need to complicate the Script Include return - just return JSON.stringify(result); - but if you want to do this, you may need to include 'result' in the setValue lines, which don't look at all correct but we'll get there once the other items are addressed.