The CreatorCon Call for Content is officially open! Get started here.

Business rule to update the asset warranty expiration date as per the contract ends date

ZODE
Tera Contributor

Hi All,

 

I have a requirement where we need to update the asset's 'warranty_expiration' date (alm_asset) as per the contract 'ends' date. We have a business rule for this requirement. The below business rule works when we add the asset to the related list ('clm_m2m_contract_asset') of the contract. The asset's 'warranty_expiration' date changes as per contract's 'ends' date,  but it doesn't change the warranty_expiration date when the contract.ends date is changed on the contract record. How I modify my business rule to make it work?

 

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

var assetGR = new GlideRecord('alm_asset');
var assetExists = assetGR.get(current.asset);

if (assetExists) {
var warrantyExpiration = assetGR.getValue('warranty_expiration');
var contractEnds = new GlideDateTime(current.contract.ends);

if (!warrantyExpiration || warrantyExpiration != contractEnds || current.contract.ends.changes()) {
assetGR.setValue('warranty_expiration', contractEnds);
assetGR.update();
}
}
})(current, previous);

 

 

2 REPLIES 2

Harshal Aditya
Mega Sage

Hi @ZODE ,

 

Hope you are doing well.

Instead of using get method could you please use addQuery.

 

var assetGR = new GlideRecord('alm_asset');
assetGR.addQuery("sys_id",current.asset);

if (assetGR) {

//Rest of your code

}

 

Please Mark My Response as Correct/Helpful based on Impact

Regards,
Harshal

ZODE
Tera Contributor

Hi Harshal,

 

I am good, thanks. Hope you are well too! I tried with addQuery but it doesnt work.