- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 01:16 AM
Hello Expert,
I need help one of my existing issue:
I have created a scheduled script where I want to achieve this:
Support group and Managed by group should automatically update when changing Technical Service offering fields.
Can anyone help with this what's the best method to achieve this? Do I need to run the server-side script or can we achieve it via business rule?
I can share the current code, what I have written, but unfortunately it's not working.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 06:55 AM - edited 02-14-2023 06:56 AM
Are you familiar with a Service Offering has a CI relationship of maintains with a dynamic CI group? This will pass through group information from the Service Offering to the CIs within the Dynamic CI group, no custom script needed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 08:07 AM
You can try this as example, I added supported_by attribute
Business Rule: CSDM - Sync Group Attributes
(function executeRule(current, previous /*null when async*/ ) {
var prevValues = {}; var updateWithValues = {};
if (current.support_group.changes()) { updateWithValues.support_group = current.getValue('support_group'); prevValues.support_group = previous.getValue('support_group'); } if (current.assignment_group.changes()) { updateWithValues.assignment_group = current.getValue('assignment_group'); prevValues.assignment_group = previous.getValue('assignment_group'); } //New if (current.supported_by.changes()) { updateWithValues.supported_by = current.getValue('supported_by'); prevValues.supported_by = previous.getValue('supported_by'); }
if (current.managed_by_group.changes()) { updateWithValues.managed_by_group = current.getValue('managed_by_group'); prevValues.managed_by_group = previous.getValue('managed_by_group'); }
if(JSUtil.nil(updateWithValues) || Object.keys(updateWithValues).length == 0) return;
gs.eventQueue('csdm.tso.modified', current, JSON.stringify(prevValues), JSON.stringify(updateWithValues), 'sn_csdm_tso_queue');
gs.addInfoMessage(gs.getMessage('Data sync is activated for Change Group, Support Group, Supported By and Managed By Group fields.') + " <a href='/api/now/v1/context_doc_url/enable-datasync' target='_blank'>" + gs.getMessage('Learn more') + "</a>");
})(current, previous);
|
sysauto_script: CSDM Data sync
/******** Sync MBG from class to newly created CIs - Start ********/
// fetch all class info records with managed by group var grCmdbClassInfo = new GlideRecord("cmdb_class_info"); var didUpdate; grCmdbClassInfo.addNotNullQuery("managed_by_group"); grCmdbClassInfo.query();
while(grCmdbClassInfo.next()) { // apply MBG to CIs in each specific class created in last 25 hours var grCmdbCi = new GlideRecord("cmdb_ci"); grCmdbCi.addEncodedQuery("sys_created_on>javascript:gs.hoursAgo(25)^managed_by_groupISEMPTY^sys_class_name=" + grCmdbClassInfo.getValue("class")); grCmdbCi.query(); if (grCmdbCi.hasNext()) { grCmdbCi.setValue("managed_by_group", grCmdbClassInfo.getValue("managed_by_group")); grCmdbCi.updateMultiple(); didUpdate = true; } } if (didUpdate) { gs.log("Completed updating new CIs with Managed By Group"); } /******** Sync MBG from class to newly created CIs - End ********/
/******** Sync SG, CG, MBG from newly created ci relationship between TSO and DCG ********/ var oldValues = {'support_group':'','assignment_group':'','supported_by':'','managed_by_group:':''}; var grRel = new GlideRecord('cmdb_rel_ci'); grRel.addEncodedQuery('sys_created_on>javascript:gs.hoursAgo(25)'); grRel.addEncodedQuery('parent.sys_class_name=service_offering^child.sys_class_name=cmdb_ci_query_based_service'); grRel.query(); while(grRel.next()) { if(util.isTechnicalService(grRel.getValue('parent')) && util.isTechnicalService(grRel.getValue('child'))) { var tso = new GlideRecord('service_offering'); if (!tso.get(grRel.getValue('parent'))) continue;
var newValues = {}; newValues.support_group = tso.getValue('support_group'); newValues.assignment_group = tso.getValue('assignment_group'); //NEW newValues.supported_by = tso.getValue('supported_by');
if (tso.getValue('managed_by_group')) { // prevents overriding CI class MBG value with blank newValues.managed_by_group = tso.getValue('managed_by_group'); } gs.eventQueue('csdm.tso.modified', tso, JSON.stringify(oldValues), JSON.stringify(newValues), 'sn_csdm_tso_queue'); } } /******** End - Sync SG, CG, MBG from newly created ci relationship between TSO and DCG ********/
/********* Sync values(SG,CG,MBG) for new CIs getting added to DCG - Start *********/ var grAssoc = new GlideRecord('svc_ci_assoc'); grAssoc.addEncodedQuery('service_id.sys_class_name=cmdb_ci_query_based_service^service_id.service_classification=Technical Service^sys_created_on>javascript:gs.hoursAgo(25)'); grAssoc.query(); var svcCiMap = {}; while(grAssoc.next()) { var cis = svcCiMap[grAssoc.getValue('service_id')]; if(!cis) cis = []; cis.push(grAssoc.getValue('ci_id')); svcCiMap[grAssoc.getValue('service_id')] = cis; }
// Check if DCG is connected to any TSO var validDcgSysIds = []; var map = util.getAssocTSOsFromDCG(Object.keys(svcCiMap)); Object.keys(map).forEach(function(v){ validDcgSysIds = validDcgSysIds.concat(map[v]); });
// Update values from DCG to CIs var grDCG = new GlideRecord('cmdb_ci_query_based_service');
validDcgSysIds.forEach(function(dcgSysId) { grDCG.get(dcgSysId); var updateWithValues = { 'support_group' : grDCG.getValue('support_group'), 'assignment_group' : grDCG.getValue('assignment_group'), 'supported_by' : grDCG.getValue('supported_by'),
}; // prevents overriding ci class manager value if blank if (grDCG.getValue('managed_by_group')) { updateWithValues['managed_by_group'] = grDCG.getValue('managed_by_group'); } util.updateRecords('cmdb_ci', svcCiMap[dcgSysId], updateWithValues);
gs.log("Completed updating CIs from DCIG"); });
/********* Sync values(SG,CG,MBG) for new CIs getting added to DCG - End *********/
|

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 06:37 AM
Can you explain what you want to achieve?
1
Do you need to change the Support Group and the Managed by Group of the Technical Service Offering if any field in the Technical Service Offering is changing? (why?)
or
2
Do you need to change the Support Group and the Managed by Group of the related CIs when the Support Group and the Managed by Group of the related Technical Service Offering are changing? (this could be standard)
BR,
Barry

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 06:55 AM - edited 02-14-2023 06:56 AM
Are you familiar with a Service Offering has a CI relationship of maintains with a dynamic CI group? This will pass through group information from the Service Offering to the CIs within the Dynamic CI group, no custom script needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 03:26 AM
Hello @EricDohr, Thank you so much, for the given solution. It's working now!
But I am having another additional requirement, just like after this configuration, these support group are populating now,
- Support group
- Change group
- Managed by group
I also want to populate the approval group, assignment group, Managed by and owned by attribute values as well. Kindly help to achieve this.
I have tried to make some changes in "CSDM Data Sync" but its not working, attaching SS here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 08:07 AM
You can try this as example, I added supported_by attribute
Business Rule: CSDM - Sync Group Attributes
(function executeRule(current, previous /*null when async*/ ) {
var prevValues = {}; var updateWithValues = {};
if (current.support_group.changes()) { updateWithValues.support_group = current.getValue('support_group'); prevValues.support_group = previous.getValue('support_group'); } if (current.assignment_group.changes()) { updateWithValues.assignment_group = current.getValue('assignment_group'); prevValues.assignment_group = previous.getValue('assignment_group'); } //New if (current.supported_by.changes()) { updateWithValues.supported_by = current.getValue('supported_by'); prevValues.supported_by = previous.getValue('supported_by'); }
if (current.managed_by_group.changes()) { updateWithValues.managed_by_group = current.getValue('managed_by_group'); prevValues.managed_by_group = previous.getValue('managed_by_group'); }
if(JSUtil.nil(updateWithValues) || Object.keys(updateWithValues).length == 0) return;
gs.eventQueue('csdm.tso.modified', current, JSON.stringify(prevValues), JSON.stringify(updateWithValues), 'sn_csdm_tso_queue');
gs.addInfoMessage(gs.getMessage('Data sync is activated for Change Group, Support Group, Supported By and Managed By Group fields.') + " <a href='/api/now/v1/context_doc_url/enable-datasync' target='_blank'>" + gs.getMessage('Learn more') + "</a>");
})(current, previous);
|
sysauto_script: CSDM Data sync
/******** Sync MBG from class to newly created CIs - Start ********/
// fetch all class info records with managed by group var grCmdbClassInfo = new GlideRecord("cmdb_class_info"); var didUpdate; grCmdbClassInfo.addNotNullQuery("managed_by_group"); grCmdbClassInfo.query();
while(grCmdbClassInfo.next()) { // apply MBG to CIs in each specific class created in last 25 hours var grCmdbCi = new GlideRecord("cmdb_ci"); grCmdbCi.addEncodedQuery("sys_created_on>javascript:gs.hoursAgo(25)^managed_by_groupISEMPTY^sys_class_name=" + grCmdbClassInfo.getValue("class")); grCmdbCi.query(); if (grCmdbCi.hasNext()) { grCmdbCi.setValue("managed_by_group", grCmdbClassInfo.getValue("managed_by_group")); grCmdbCi.updateMultiple(); didUpdate = true; } } if (didUpdate) { gs.log("Completed updating new CIs with Managed By Group"); } /******** Sync MBG from class to newly created CIs - End ********/
/******** Sync SG, CG, MBG from newly created ci relationship between TSO and DCG ********/ var oldValues = {'support_group':'','assignment_group':'','supported_by':'','managed_by_group:':''}; var grRel = new GlideRecord('cmdb_rel_ci'); grRel.addEncodedQuery('sys_created_on>javascript:gs.hoursAgo(25)'); grRel.addEncodedQuery('parent.sys_class_name=service_offering^child.sys_class_name=cmdb_ci_query_based_service'); grRel.query(); while(grRel.next()) { if(util.isTechnicalService(grRel.getValue('parent')) && util.isTechnicalService(grRel.getValue('child'))) { var tso = new GlideRecord('service_offering'); if (!tso.get(grRel.getValue('parent'))) continue;
var newValues = {}; newValues.support_group = tso.getValue('support_group'); newValues.assignment_group = tso.getValue('assignment_group'); //NEW newValues.supported_by = tso.getValue('supported_by');
if (tso.getValue('managed_by_group')) { // prevents overriding CI class MBG value with blank newValues.managed_by_group = tso.getValue('managed_by_group'); } gs.eventQueue('csdm.tso.modified', tso, JSON.stringify(oldValues), JSON.stringify(newValues), 'sn_csdm_tso_queue'); } } /******** End - Sync SG, CG, MBG from newly created ci relationship between TSO and DCG ********/
/********* Sync values(SG,CG,MBG) for new CIs getting added to DCG - Start *********/ var grAssoc = new GlideRecord('svc_ci_assoc'); grAssoc.addEncodedQuery('service_id.sys_class_name=cmdb_ci_query_based_service^service_id.service_classification=Technical Service^sys_created_on>javascript:gs.hoursAgo(25)'); grAssoc.query(); var svcCiMap = {}; while(grAssoc.next()) { var cis = svcCiMap[grAssoc.getValue('service_id')]; if(!cis) cis = []; cis.push(grAssoc.getValue('ci_id')); svcCiMap[grAssoc.getValue('service_id')] = cis; }
// Check if DCG is connected to any TSO var validDcgSysIds = []; var map = util.getAssocTSOsFromDCG(Object.keys(svcCiMap)); Object.keys(map).forEach(function(v){ validDcgSysIds = validDcgSysIds.concat(map[v]); });
// Update values from DCG to CIs var grDCG = new GlideRecord('cmdb_ci_query_based_service');
validDcgSysIds.forEach(function(dcgSysId) { grDCG.get(dcgSysId); var updateWithValues = { 'support_group' : grDCG.getValue('support_group'), 'assignment_group' : grDCG.getValue('assignment_group'), 'supported_by' : grDCG.getValue('supported_by'),
}; // prevents overriding ci class manager value if blank if (grDCG.getValue('managed_by_group')) { updateWithValues['managed_by_group'] = grDCG.getValue('managed_by_group'); } util.updateRecords('cmdb_ci', svcCiMap[dcgSysId], updateWithValues);
gs.log("Completed updating CIs from DCIG"); });
/********* Sync values(SG,CG,MBG) for new CIs getting added to DCG - End *********/
|