UI action to add user to the group

GB14
Kilo Patron

I tried creating a UI action to add the user to the group but the button won't do anything on click. 

I created the UI action on the sys_user table and added the below script but nothing is happening. Nothing in the logs either. Any suggestions?

 

 

 

var rec = new GlideRecord('sys_user_grmember');
rec.initialize();
rec.user = current.user.sys_id;
rec.group = '9da403d8979fdd103749312e2153af7e'; //group ABC
rec.insert();

 

 

 

1 ACCEPTED SOLUTION

Hi @GB14 

 

can you please uncheck client checkbox and try that will work.

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Regards,

Ranjit Nimbalkar

 

View solution in original post

7 REPLIES 7

Ratnakar7
Mega Sage
Mega Sage

Hi @GB14 ,

 

->> Verify that the group ID you are using in the script is correct and exists in the system. You can find the correct group ID by navigating to the group record and checking its sys_id value in the URL.

 

->>Check the ACLs (Access Control Rules) for the sys_user_grmember table to ensure that the current user has the necessary privileges to create new records in this table.

 

->>Check the UI action's conditions to make sure they are not preventing the action from being executed. You can try temporarily removing the conditions to see if the UI action works.

 

->>Add some error handling to your script to display a message to the user if the insert operation fails.

For example:

var rec = new GlideRecord('sys_user_grmember');
 rec.initialize(); 
rec.user = current.user.sys_id; 
rec.group = '9da403d8979fdd103749312e2153af7e'; //group ABC
 if (rec.insert()) { 
    gs.addInfoMessage("User added to group successfully."); 
}
 else { 
 gs.addErrorMessage("Failed to add user to group."); 
}

 

Thanks,

Ratnakar

Hello Ratnakar,

I tried but nothing happens on click. Nothing in the logs either. 

Thank you 

 

Muhammad Khan
Mega Sage
Mega Sage

Try configuring your UI Action as below.

MuhammadKhan_1-1683733236078.png