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

Yes, create a before insert business rule with condition "Anonymize response"

and use this code

current.sys_updated_by = '';

current.sys_created_by = '';

 

This will do the work

 

Mark helpful if this helped

 

Thank you,

Vikram

 

 

xinyao
ServiceNow Employee
ServiceNow Employee

Hi Vikram,

 

I tried your suggestion but I am surprised that it's not working as expected. The "sys_created_by" and "sys_updated_by" are still shown user's name. Here is my code example in our before insert/update business rule:

 

// When the survey was set up as "Anonymize response", we need to hide survey user's name
var isAnonymized = new AssessmentUtils().isAnonymized(current.getValue("metric_type"));
if (isAnonymized) {
current.sys_created_by = '';
current.sys_updated_by = '';
}

When I printed out above variables and it showed empty which is good. However, it still showed user'name at the end.

 

Thanks,

Hi xinyao,

 

On what table you have created that business rule? If it is on survey instance there is no metric_type field on that table

 

Thank you,

Vikram

 

xinyao
ServiceNow Employee
ServiceNow Employee

Hi Vikram, 

 

We do have that "metric_type" field on survey instance table. Are you familiar with "GlideSession"? Can we establish a new session for guest user in business rule?

find_real_file.png

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