current.update or gr.update in Business rules

RudhraKAM
Tera Guru

Hello ,

I have a requirement where i need to set a field to true when a RITM is created (up on checking its workflow type if condition matches then set the field on RITM to true ,, what is the best practice can some one explain me what to use and why , i saw in may posts to avoid current.update ,, what do  we need to use then ?

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

var gr=new GlideRecord('sc_cat_tem');
gr.addQuery('sys_id',current.cat_item);
gr.query();
while(gr.next())
{
var workflowtypeis=gr.u_workflow_type; 

if(workflowtypeis=='manual close')	
	
gr.u_wf_typ="true"; 
gr.update();
}

 

or 

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

var gr=new GlideRecord('sc_cat_tem');
gr.addQuery('sys_id',current.cat_item);
gr.query();
while(gr.next())
{
var workflowtypeis=gr.u_workflow_type; 

if(workflowtypeis=='manual close')	

current.u_wf_typ="true"; 
current.update();
}
7 REPLIES 7

Elijah Aromola
Mega Sage

You should just be able to set the value of current in your business rule. What table is this business rule running on?

sc_cat_item

RudhraKAM
Tera Guru

if at all if we are using current.update , do i need to use setworkflow (false); too?

Hi,

 

current.update(); if not used will not update anything from the code.

For your setworkflow (false); to be used is not required always. 

As per the 2 snippets above. First one will update the workflow type field on sc_cat_item table while the second one will update it for the current table (where business rule runs).

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.