Auto populate MVRS variable on basis of a variable outside it

Nagashree5
Tera Contributor

Hi All,

 

I'm trying to auto-populate the "SAP Cost center" variable inside the mvrs based on the option selected in a reference field called "Company code" which is outside mvrs. In the company code variable, when code is selected, the location should autopulate in the 'sap_cost_center' field which is inside a MVRS(Multi Row).

I'm trying to set the value like below, but it isn't working.

Script Include:

sap:function()
{
var companycode=this.getParameter('sysparm_company');
var gr=new GlideRecord('core_company');
gr.addQuery('name',companycode);
gr.query();
if(gr.next())
{
var ans=gr.location;
return ans;
}
},

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('populateaddress');
ga.addParam('sysparm_name', 'sap');
var com = g_form.getValue('sap_purchase');
ga.addParam('sysparm_company', com);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('sap_cost_center_mr', answer);// this is the MVRS variable
}
}

When tried with alert, we are getting the location value but unable to set the value in to the MVRS variable. Can anyone please guide me on this.

 

Thank you in Advance.

 
6 REPLIES 6

If the MRVS is populated, the first line should be retrieving a JSON formatted string of all of the variable names and values for each row, and this is the format you have to match when re-populating it with the answer value.  If the first alert is empty the MRVS internal name must not be 'multirow_variable'?

Hi @Brad Bowman  , the internal name is actually multirow_variable