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

@Samarendra Nayak 

Can you share the screen shot of your MRVS as well to help you further.

 

Regards,

Shloke

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

Regards,
Shloke

Hello Sir,

 

Please find attached screen for MRVS.

 

Thanks,

Samarendra Nayak

Ankur Bawiskar
Tera Patron

Hi,

So MRVS variables will be updated from sc_task form and once it's updated those variable information should be updated on sc_task?

u_applicable_geo, u_benefits_of_change these fields are on which table?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Actually my MRVS(u_demand_management_relese_details) is attaching to my task at the time of task create (I have UI policy to hide it from RITM form and portal page) and I want once values of the MRVS variables are updated  by an agent, it need to updates to each individual variables on sc_task table.

For example, I have one variable in my MRVS as "buid_end_date" , so I want once it updated by an agent, it need to update in a field in sc_task table called "u_actual_build_end_date".

Please suggest.

 

Thanks,

Samarendra Nayak

Hi,

so for each variable within MRVS you have corresponding field on sc_task table?

you can use after update BR on sc_task table and get the JSON; parse it and update the current record

BR Condition:

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

Script:

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

	// Add your code here
	var mrvs = current.variables.mrvsVariableName; // give name of mrvs here
	var parser = JSON.parse(mrvs);
	var gr = new GlideRecord("sc_task");
	gr.addQuery("sys_id", current.getUniqueValue());
	gr.query();
	if (gr.next()) {
		gr.u_actual_build_end_date = parser[0].buid_end_date;
		gr.u_applicable_geo = parser[0].applicable_geo;
		gr.u_applicable_org_entity = parser[0].applicable_org_entity;
		gr.u_applications = parser[0].applications;
		gr.u_benefits_of_change = parser[0].benefits_of_change;
		gr.u_estimated_saving_hours = parser[0].stimated_saving_hours_per_annum;
		gr.u_function = parser[0].function;
		gr.u_function_delivery_group = parser[0].function_delivery_group;
		gr.u_module = parser[0].module;
		gr.u_demand_priority = parser[0].Priority_demand;
		gr.u_proposed_change = parser[0].proposed_change;
		gr.u_reason_for_change = parser[0].reason_for_change;
		gr.u_request_description = parser[0].request_description;
		gr.u_request_title = parser[0].request_title;
		gr.u_demand_request_type = parser[0].request_type;
		gr.update();
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader