Need help on the Workflow script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have requirement where the 'sys_created_by' field in the 'sys_user_group' table should populate manager name.
Currently, when the group is created via AGCM, RITM gets created with some approvals, the last person to approve the RITM shows as created by in the 'sys_user_group' table.
pasting the script below
I have updated from line 32 to 39
it is not allowing to override the sys_created_by field, but for some reason it was working earlier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello @SanikaK ,
The script seems right, also add on I would recommend to initialize a fresh GlideRecord to avoid caching issues from the insert :
grRec.u_custom_type = custType;
var groupId = grRec.insert();
var usr = new GlideRecord('sys_user');
if (usr.get(manager)) {
var updateGrpRec = new GlideRecord('sys_user_group');
if (updateGrpRec.get(groupId)) {
updateGrpRec.autoSysFields(false);
updateGrpRec.setWorkflow(false);
updateGrpRec.sys_created_by = usr.user_name;
updateGrpRec.update();
}
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
earlier it was working fine and now it's not
so what changed recently?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @SanikaK,
If your requirement is strictly to populate sys_created_by with the manager's username, you can try using:
var groupId = grRec.insert();
var user = new GlideRecord('sys_user');
if (user.get(manager)) {
var group = new GlideRecord('sys_user_group');
if (group.get(groupId)) {
group.autoSysFields(false);
group.sys_created_by = user.user_name.toString();
group.update();
}
}