checking mvrs before closing catalog task

Hafila Hatta
Tera Guru

i have a requirement to do checking, to ensure multirow variable set is filled in by fulfiller and its not empty before closing the task. 

 

i created a BR and it works fine. however, once the mrvs is filled, the task still cant be closed cause in ritm side, its considered empty. 

 

how to fix this, thanks

1 ACCEPTED SOLUTION

@Hafila Hatta 

this worked for me

function onSubmit() {
   //Type appropriate comment here, and begin script below
   
	if(g_form.getValue('state') == '3'){
		var json = g_form.getValue('variables.servers'); // servers is my mrvs variable set name
		var parsedData = JSON.parse(json);
		if(parsedData.length == 0){
			alert('The multi-row variable set must not be empty before closing the task.');
			return false;
		}
	}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafila Hatta 

please share your business rule script, BR is on which table and what's the condition? some screenshots as well.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

(function executeRule(current, previous /*null when async*/) {
    // Query the sc_multi_row_question_answer table
    var gr = new GlideRecord('sc_multi_row_question_answer');
    gr.addQuery('parent_id', current.sys_id);
    gr.query();

    // Check if there are any rows
    if (!gr.hasNext()) {
        gs.addErrorMessage('The multi-row variable set must not be empty before closing the task.');
        current.setAbortAction(true); // Prevent the task from being closed
    }
})(current, previous);

heres the table and condition

HafilaHatta_0-1741323484577.png

 

@Hafila Hatta 

update this line

    gr.addQuery('parent_id', current.request_item);
 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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