Insert a record in table through script and set 'created by' to service account

kalpesh9
Mega Guru

We need to insert a record in a table through a workflow. While using Glide Record, the record is getting inserted, but the 'created by' field is getting set to the person triggering the workflow. We need to set the 'created by' field as a service account. Please let us know in case if there is any way to set the 'created by' field through the script from the workflow

2 REPLIES 2

SatyakiBose
Mega Sage

Hello @kalpesh9 

A simple way to achieve this is by scheduled job.

Setup a scheduled job, to run the script for inserting the record.

Now in the scheduled job, you have a field called Run As.

In the Run As field, you can set the value as the service account.

So whenever, the record is created, it shows created by as the service account

Sagar Pagar
Tera Patron

Hi @kalpesh9,

 

You have to use the timer activity with 3 seconds time in it. It will switch the User context to System context.

 

After that use run script activity -

 

grObject.sys_created_by = "service_account";

grObject.setWorkflow(false);

grObject.autoSysField(false);

grObject.insert();

 

 

Thanks,
Sagar Pagar

The world works with ServiceNow