- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:11 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:28 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 10:34 PM
Hey @akin9
I'm not sure if I conveyed my point clearly regarding your initial business rule. While it might work in term of functionality, it often leads to a critical problem known as recursive business rule.
The second business rule should be applied to the Contract [ast_contract] table.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:28 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 11:46 PM
Hi @Tai Vu
Working fine thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 10:28 PM
Please try with below code in after update business also apply some log
(function executeRule(current, previous /*null when async*/) {
try {
if (current.contract.starts.changes() || current.contract.ends.changes()) {
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();
gs.info("Updated asset record with lease contract dates");
} else {
gs.info("No asset record found for the given asset sys_id: " + current.asset);
}
}
} catch (ex) {
gs.error("An error occurred while updating asset record: " + ex);
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks