Need help on the Workflow script

SanikaK
Tera Expert

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

SanikaK_0-1780979514220.pngSanikaK_1-1780979537062.png

SanikaK_2-1780979561018.png



it is not allowing to override the sys_created_by field, but for some reason it was working earlier.

3 REPLIES 3

yashkamde
Mega Sage

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.

Ankur Bawiskar
Tera Patron

@SanikaK 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

pr8172510
Tera Guru

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();
    }
}