Business Rule is executed it is showing user name who initiated the transaction

GauravD02478352
Tera Contributor

I want to have updated by as system user when update transaction is happening via Business Rule.

 

When BR is executed it is taking user who initiated the transaction in updated by field I want to change it to system or some other user.

1 ACCEPTED SOLUTION

Akshay Gupta2
Kilo Sage
 
Please use this code snippet in your Business Rule Script for update.
 
Steps -
1. Before Updating impersonate as - system user or admin .
2. At the last line of your end impersonation.
 

 

 var currentUser = gs.getUserID(); // store currently logged in user to end the impersonation
        var impUser = new GlideImpersonate();
        impUser.impersonate(gs.getProperty("ib.sysAdminUserSysId")); // property holds value of system user sysid
/*
Your Code -- 
*/
 /** end impersonation */
    impUser.impersonate(currentUser);​

 

 

Please mark this as solution and helpful.

 

Thanks

Akshay

View solution in original post

2 REPLIES 2

Rajesh Chopade1
Mega Sage

Hi @GauravD02478352 

 

you need to add following code in your BR:

// Store the current user
    var originalUser = gs.getUserID();

    // Set the session to the system user (or a specific user)
    gs.getSession().impersonate('system'); // Use 'system' for the system user or replace with a specific user ID

    // Perform the updates
    current.short_description = "Updated by Business Rule as System User"; // Example update
    current.update(); // Perform any other updates as needed

    // Revert back to the original user
    gs.getSession().impersonate(originalUser);

 

I hope my answer helps you to resolve your issue if yes, mark my answer helpful & correct.

THANK YOU

rajesh chopade

Akshay Gupta2
Kilo Sage
 
Please use this code snippet in your Business Rule Script for update.
 
Steps -
1. Before Updating impersonate as - system user or admin .
2. At the last line of your end impersonation.
 

 

 var currentUser = gs.getUserID(); // store currently logged in user to end the impersonation
        var impUser = new GlideImpersonate();
        impUser.impersonate(gs.getProperty("ib.sysAdminUserSysId")); // property holds value of system user sysid
/*
Your Code -- 
*/
 /** end impersonation */
    impUser.impersonate(currentUser);​

 

 

Please mark this as solution and helpful.

 

Thanks

Akshay