Updating variables values in a MRVS(sc_multi_row_question_answer) to sc_task table fields

Samarendra Naya
Kilo Contributor

Hello All,

I have a requirement of updating  all my variables values in a MRVS(sc_multi_row_question_answer) for a particular catalog item to sc_task table fields and i am trying with business rules as below which is not working.

 

Condition : current.variables.changes() && current.request_item.cat_item.name == 'Demand Management Request'

(function executeRule(current, previous /*null when async*/) {


var gr = new GlideRecord('sc_multi_row_question_answer');
gr.addQuery('parent_id',current.request_item);
gr.query();
while (gr.next()) {
gr.variable.u_actual_build_end_date = current.variable.buid_end_date;
gr.u_applicable_geo = current.variables.applicable_geo;
gr.u_applicable_org_entity = current.variables.applicable_org_entity;
gr.u_applications = current.variables.applications;
gr.u_benefits_of_change = current.variables.benefits_of_change;
gr.u_estimated_saving_hours = current.variables.estimated_saving_hours_per_annum;
gr.u_function = current.variables.function;
gr.u_function_delivery_group = current.variables.function_delivery_group;
gr.u_module = current.variables.module;
gr.u_demand_priority = current.variables.Priority_demand;
gr.u_proposed_change = current.variables.proposed_change;
gr.u_reason_for_change = current.variables.reason_for_change;
gr.u_request_description = current.variables.request_description;
gr.u_request_title = current.variables.request_title;
gr.u_demand_request_type = current.variables.request_type;

}


})(current, previous);

 

Please suggest.

 

Thanks,

Nayak

11 REPLIES 11

shloke04
Kilo Patron

@Samarendra Nayak 

Write a Business Rule based on the condition needed in your case (as it is not mentioned in your case when do you want to copy the MVRS, so can't suggest Before/After here) .

You can get the value of MVRS using the sample code shared below:

var mrvs;

var taskGR = new GlideRecord('sc_task');
if (taskGR.get(current.sys_id)) {
    mrvs = taskGR.variables.VariableName; // Pass the Internal Name of your MRVS here
}
gs.print(mrvs);
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
	var row = mrvs.getRow(i);
	current.Field1 = row.VAR1;
	current.Field2 = row.Var2;
	
}

There is a good article from Brad Tilton on this where I have taken this reference from, might be worth reading as well:

https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hello Sir,

 

Actually My MRVS(Demand Management Release Details) is attaching to my task at the time of task create (I have UI policy to hide from RITM and portal) and I want once values of the MRVS variables are updated  by an agent, it need to updates to sc_task table.

 

Thanks,

Samarendra Nayak

@Samarendra Nayak 

In that scenario you need to follow below steps:

1) Create a On Change Catalog Client Script on your Catalog Item and select the variable on change of which you want to copy the value and make sure to check the checkbox named as "Apply on Catalog task" as shown below and then use the script below:

var gr = JSON.parse(g_form.getValue('Internal Name of MRVS Variable set'));
alert(gr);

You can see the parsed value in the alert and then just set it in the field you want using the below line as :

g_form.setValue();

 

Let me know if you are stuck and share the On Change script which you have written to assist you further.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hello Sir,

 

Thanks for replay,

I have tried as per above but I am not seeing my MRVS variables to select at variable name drop down.

Please find attached screen and suggest further.

 

Thanks,

Samarendra Nayak