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

Hi @Vladimir6 
The managed_by_group field is likely a reference field that requires a valid sys_id. If current.variables.managed_by_group is not a valid sys_id or is in the wrong format, the field won't be set correctly.
Replace this in your code:

 

 

win.managed_by_group = current.variables.managed_by_group.sys_id; // Ensure this is a sys_id

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you!!

Thank you Satishkumar B, I tried as below, allthough without success:

win.managed_by_group = current.variables.managed_by_group.getUniqueValue();

Brad Bowman
Kilo Patron
Kilo Patron

To clarify, a pause timer at the beginning of a workflow, does not necessarily ensure that the entire workflow will run as System.  If there is an approval, Catalog Task, or other user interaction prior to this Run Script, add another timer just before this Run Script activity to ensure that it is running as System.  You can always log the current user in the Run Script so that you know for sure.  In your test cases, are you using the same value to populate the managed_by_group variable?  Are there any other differences in the test cases - user executing it, values supplied,...?

Hello Brad,

one of 10 success can be just a manual intervention of another user. I mentioned them because I run out of options like BR Debugging and try/catch.

 

I start the WF through the ATF with same values. There are also real runs with different Managed by group -variable, also without success. CIs are "sys_created_by" system, but also ITIL users are able to create or update them, so it is not important.