Auto update record date

akin9
Tera Contributor

Hello Experts,

We have Contracts and under contract related lists "Assets covered" are there

created Before BR insert /update to update the start and end dates its working fine.

Before BR insert /update

Table - clm_m2m_contract_asset

 

Requirement

Same w want to achieve for the after update the dates needs to update automatically.

We have tried but no luck, kindly support..

 

(function executeRule(current, previous /*null when async*/) {
	var recordUpdated=false;
	var asset = new GlideRecord("alm_asset");
	asset.addQuery('sys_id',current.asset+"");
	asset.query();
	if (asset.next()){
		if (current.contract.starts!=""){
			asset.u_lease_contract_start=current.contract.starts+" 00:00:01";
		}
		if (current.contract.ends!=""){
			asset.u_lease_contract_end=current.contract.ends+" 23:59:59";
		}
		asset.u_lease_contract=true;
		asset.update();	
	}
})(current, previous);

 

1 ACCEPTED SOLUTION

Hi @akin9 

Oops. Just correct these line below. it should do the trick.

grAsset.u_lease_contract_start=current.starts+" 00:00:01";
grAsset.u_lease_contract_end=current.ends+" 23:59:59";

 

Cheers,

Tai Vu

View solution in original post

10 REPLIES 10

Amit Verma
Kilo Patron
Kilo Patron

Hi @akin9 

 

Are you getting any error ? Did you checked if your Business rule is being called or not ? I would suggest you to check via Business Rule Debugger whether your Business rule is getting fired or not ? Also, do check for any conflicts with other existing business rules.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

akin9
Tera Contributor

Hi @Amit Verma 

Thanks for Quick reply!

above script is working fine its for before inset/update/

same i want to achieve for after date field changes script

Tai Vu
Kilo Patron
Kilo Patron

Hi @akin9 

Since you're performing update related, your business rule above should be an After one, that runs on the clm_m2m_contract_asset table.

Ref: Prevent Recursive Business Rules

 

And to handle the date get changes on the contract table, you can have one more after rule that will query all asset covered and update it.

Sample.

After/Async insert/update

Conditions: Start date changes || End date changes

 

(function executeRule(current, previous /*null when async*/) {
	
	var gr = new GlideRecord('clm_m2m_contract_asset');
	gr.addQuery('contract', current.getUniqueValue());
	gr.query();
	while(gr.next()){
		var grAsset = gr.asset.getRefRecord();
		if(grAsset.isValidRecord()){
			grAsset.u_lease_contract_start=current.contract.starts+" 00:00:01";
			grAsset.u_lease_contract_end=current.contract.ends+" 23:59:59";
			grAsset.u_lease_contract=true;
			grAsset.update();
		}
	}

})(current, previous);

 

 

Cheers,

Tai Vu

 

akin9
Tera Contributor

Hi @Tai Vu ,

Thanks for the quick reply!

Already My above script Before BR is running fine. that's also needed.

now contract extended and date is updated same need to populate on 

related lists "Assets covered".

I have tried the script unfortunately not working. pls correct me if wrong

akin9_0-1709790937858.pngakin9_1-1709790973409.png