Can't set 'Managed by group' field on a Win Server CI through the script

Vladimir6
Tera Expert

Dear all,

we are creating a Windows Server CI through the script in the workflow. The field Managed by group stays empty. Audit shows no changes in the field happening. Same variable returns the value nicely in another field (comments). The workflow has a pause tiemer in the beginning, so it runs as a System. Interestingly also, 1 time out of 7-10 the field will be filled. Any ideas?

 

//Create a Win Server
var win = new GlideRecord('cmdb_ci_win_server');
win.initialize();
win.support_group = 'fixed_sys_id'; //this works
win.managed_by_group = current.variables.managed_by_group; //the field stays empty
win.comments = "Managed by application group " + current.variables.managed_by_group.name; //this works
var winServId = win.insert();

 

 

1 ACCEPTED SOLUTION

We found the problem. Business rule "CSDM Data Sync on Reclassification" is wrongly clearing CI "managed_by_group" field, thinking that the class has been chancghed, even if the CI is created.

https://www.servicenow.com/community/itom-forum/business-rule-quot-csdm-data-sync-on-reclassificatio...

View solution in original post

13 REPLIES 13

Satishkumar B
Giga Sage
Giga Sage

Can you add a log and see the value for "win.managed_by_group"

Sure, works as a charm

"Generic buildplan WF has updated the server svr34539529 with Managed by group "group name""

var win = new GlideRecord('cmdb_ci_win_server');
win.get(workflow.scratchpad.cmdb_ci_win_server);
win.setValue('managed_by_group', current.variables.managed_by_group);
gs.info("generic buildplan WF has updated the server " + win.name + " with Managed by group " + current.variables.managed_by_group.name);
try {
gs.info("Generic build plan WF updated the server " + win.update() + " with value " + win.getDisplayValue('managed_by_group'));
} catch (e) {
gs.error("generic buildplan WF thrown an error: " + e);
}

Since this is a CSDM field, there could be some added protection/security measures.  In your update script, try taking out the try/catch, leaving just the win.update() with a previous line to ensure no Business Rules are running:

var win = new GlideRecord('cmdb_ci_win_server');
if (win.get(workflow.scratchpad.cmdb_ci_win_server) {
    win.setWorkflow(false);
    win.setValue('managed_by_group', current.variables.managed_by_group); 
    win.update();
}

If that doesn't work, try the same with the table 'cmdb_ci'.

Hi Brad,

think you for your support. Unfortunately, neither of suggestions has helped.