Is it appropriate to use gr.update() in a Business Rule to update a record on a different table?

sleepycrown
Giga Guru

Hey everyone,

 

I know that current.update() is not a best practice when working with business rules, but is it appropriate to use gr.update() in a business rule to update a record on another table?

 

In my example, I have an 'after' business rule that runs on sc_request but updates the RITMS that are created with that request. 

	var relatedItemsInfo = [];
	var item = new GlideRecord('sc_req_item');
	item.addQuery('request',current.sys_id);
	item.query();
	while (item.next()) {
		relatedItemsInfo.push(item.number + ': ' + item.short_description);
	}
	var updateItem = new GlideRecord('sc_req_item');
	updateItem.addQuery('request', current.sys_id);
	updateItem.query();
	while (updateItem.next()) {
		var relatedNote = 'Note to include.' + '\n' + relatedItemsInfo.join('\n');
		updateItem.comments = relatedNote;
		updateItem.update();
	}

Is my use of updateItem.update() the best way to do this or should I be updating that record in a different way?

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi,

 

What you have is fine. Your observation on the use of 'current.update()' is correct, but doesn't apply here since the record is on another table. One consideration is do you want business rules on sc_req_item table to run when you update a record there? If not add 'updateItem.setWorkflow(false);' before the update().  Others here may post their thoughts.

View solution in original post

3 REPLIES 3

Bert_c1
Kilo Patron

Hi,

 

What you have is fine. Your observation on the use of 'current.update()' is correct, but doesn't apply here since the record is on another table. One consideration is do you want business rules on sc_req_item table to run when you update a record there? If not add 'updateItem.setWorkflow(false);' before the update().  Others here may post their thoughts.

Thanks very much, Bert!

Bert_c1
Kilo Patron

See: KB0713029

on the use of 'gr' as a GlideRecord variable name.