Alternative of current.update in BR

Munna1
Tera Contributor

Hi,

As per my requirement it has to create the task and RITM and link the task and RITM in the task related list. but if we remove the current.update it stopping  to create the task. I tried with GlideRecod of task table, but still not showing the task and ritm in task related list. Is there any work around this current.update()..

 

insertm2m();

function insertm2m() {
var assetRITM = new GlideRecord('u_m2m_tasks_assets');
assetRITM.initialize();
assetRITM.u_task = current.sys_id;
if(current.cmdb_ci.changes()){ // ci changes respective asset
assetRITM.u_asset = current.cmdb_ci.asset;
insertLink(current.cmdb_ci.asset);
}
if(assetRITM.u_asset != '' && assetRITM.u_task != '')
assetRITM.insert();

//link to asset and ritm
function insertLink(asset){
if(asset != '' ){
var upt_Asset = new GlideRecord('alm_hardware');
upt_Asset.addQuery('sys_id', asset);
upt_Asset.query();
if(upt_Asset.next()){
upt_Asset.work_notes = "Linked Task - [code]<a href='/task.do?sys_id="+current.sys_id+"'target = _blank'>"+current.number+"</a>[/code]" ;
upt_Asset.update();


 //current.update();


// var link_asset = new GlideRecord('task');
// link_asset.addQuery('sys_id',current.sys_id);
// link_asset.query();
// if(link_asset.next()){
// link_asset.update();
// }
              }
       }
   }
}

2 REPLIES 2

Prince Arora
Tera Sage
Tera Sage

@Munna1 

 

Can you make the business rule

Before - update

 

Instead of

After-update

 

PrinceArora_0-1683618411909.png

 

 

You don't need to add current.update() in before Update Business rule

 

Please let me know if it works for you!

 

 

Sandeep Rajput
Tera Patron
Tera Patron

@Munna1 Is there any specific reason why you chose to create an onAfter business rule? Ideally it should have been onBefore business rule which will allow you to not to use current.update();

 

If there are reasons to have this business rule OnAfter then write current.update() as follows.

 

current.setWorkflow(false);
current.update();

 

This will prevent the recursion among the business rule calls.