How can we anonymize "sys_updated_by" and "sys_created_by" user fields?

xinyao
ServiceNow Employee
ServiceNow Employee

Once we define a survey as "Anonymize response", we want to hide survey user' name on whatever records related to their response, such as "survey instance" table. However, survey user's name is still shown in the fields of "sys_updated_by" and "sys_created_by" on the response records. These two user fields are controlled by platform mechanism and they will be updated automatically by current logged in user.

The solution we have been trying is to use "impersonate" functionality. We tried to impersonate as 'Guest' user when taking anonymize survey. However, it's not going to work either because "impersonate" is not allowed for all login users. For example, 'Abel Tuter' cannot impersonate as 'Guest' user.

Do we have any anonymous mode to solve this issue? Thanks in advance!

 

1 ACCEPTED SOLUTION

Vikram Reddy
Giga Guru

Hi xinyao,

Use this script for after business rule on 'asmt_assessment_instance_question'

set conditions on when to run

var a = current.instance.sys_updated_by;
var b = current.instance.sys_created_by;

if(a || b){
var gr = new GlideRecord('asmt_assessment_instance');
gr.get(current.instance);
gr.autoSysFields(false);
gr.sys_updated_by = '';
gr.sys_created_by= '';
gr.update();

}
current.autoSysFields(false);
current.sys_updated_by = '';
current.sys_created_by= '';

current.update();

 

Thank you,

Vikram

 

View solution in original post

13 REPLIES 13

xinyao
ServiceNow Employee
ServiceNow Employee

Thank you so much for the help! One question, is this for "after update" business rule? Will "current.update()" cause an infinite loop for updating it? If this is for "after insert" business rule, then what will happen when we update instance question?

Yes this is after insert.

"current.update()" will cause an infinite loop for updating when used in before but not in 'after' business rules. Because in before business rules system however executes current.insert() or current.update() and if you again specify it creates an infinite loop triggering the business rule until it exhausts

If you update the record the business rules wouldnt trigger and need not worry about it as at the time of insertion we are clearing out those 2 fields. If you don't want to see sys_updated_by after updating, include after update in the business rule.

xinyao
ServiceNow Employee
ServiceNow Employee

So appreciate! Nice explanation.

Glad it helped, Please connect with me on Linkedin

www.linkedin.com/in/vikram-reddy-b48047144

Just trying to grow my network in ServiceNow space

 

Thank you,

Vikram