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

sorry jaspal ,, I didn't understand this

 

"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)."

Hi,

 

The first snippet

(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();
}

would execute the update function on sc_cat_item table. i.e. the table that is Gliderecorded with variable gr.

 

Other one

(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();
}

will update the table that is selected in the Business rule form.

 

So, for e.g. If my Business rule runs on RITM (current) table then snippet 1 would update the table gliderecorded i.e. sc_cat_item while the snippet 2 will update the RITM (current) table.

 

Hope this helps.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

SaiRaviKiran Ak
Giga Guru

It would be best to use gr.update(); in this case as you glide recorded the sc_cat_tem table