Business rule not updating the relationship type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 11:13 PM
Hi Experts,
I am writing one after business rule on cmdb_ci_service_discovered table to update relationship type in cmdb_rel_ci table.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rel = new GlideRecord('cmdb_rel_ci');
{
rel.addQuery('child', current.sys_id);
rel.addQuery('type', '55c95bf6c0a8010e0118ec7056ebc54d');
rel.query();
if(rel.next())
{
gs.log("test" + rel.getDisplayValue('type'));
rel.type = '41008aa6ef32010098d5925495c0fb94';
rel.update();
gs.log("demo" + rel.getDisplayValue('type'));
}
}
})(current, previous);
But its not updating the record in the cmdb_rel_ci table. Is it like I would have to add new record and delete the existing one to achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 12:50 AM
Hi,
try this and share the updates
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('child', current.sys_id);
re.addQuery('type', '55c95bf6c0a8010e0118ec7056ebc54d');
rel.query();
if(rel.next())
{
gs.info("Record found");
rel.type = '41008aa6ef32010098d5925495c0fb94';
rel.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 01:45 AM
Hi Ankur,
I corrected the code as per your and Tony recommendation still its not updating the relationship. Also, I am not getting anything in the system log. I am using UI action "Convert to Application Service" to convert Business service. It is inserting one record in mapped application service table but the relationship is still "Contains::Contained by". It should change it to "Consumes::Consumed by" as per the business rule. Could please help me in this regard. Let me know if you need further input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 11:24 PM
Try to debug by adding gs.info() statements.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 12:54 AM
Hi, you have an error on this line
re.addQuery('type', '55c95bf6c0a8010e0118ec7056ebc54d');
missing the l from rel, try
rel.addQuery('type', '55c95bf6c0a8010e0118ec7056ebc54d');
Also there are a couple of {} that are not needed, and I recommend that you use the syntax of the example provided by Ankur Bawiskar