The CreatorCon Call for Content is officially open! Get started here.

Update updated by with the help of background script / Business Rule on SCTASK

Mukul Sharma
Tera Contributor

Hi All,

 

Whenever anyone update the sctask updated by name should be specific user in worknotes.

 

Like if User A update the sctask and added "abcd" in worknotes then abel tutor name should be come.

 

I am using below background script but somehow it is not working:

 

var ri = new GlideRecord('sc_task');
        ri.addQuery('sys_id', 'b452e08d4715d2109add3833e16d43fa'); //sys id of sctask
        ri.query();
        if(ri.next()){
           
        ri.work_notes = "Asset state updated successfully in Asset Explorer.";
        ri.sys_updated_by = "abel.tuter";
        gs.print(ri.sys_updated_by);
        ri.update();
            }
3 REPLIES 3

Astik Thombare
Tera Sage
Tera Sage

Hi @Mukul Sharma ,

 

I don't think we can update some system fields like updated by , created by . refer below KB article and according to it

 

Some system fields like below does not get updated from Some old value to a new value through any APIs or Scripts manually!!

1. Updated by
2. Created by 

 

KB Article - https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0859763

 

However , as a workaround you can create Scheduled Script Execution .In it we have option to Run As (By default it is not present on form  you need to add it ). Please check below screenshots 

 

AstikThombare_0-1729012857210.png

 

Result 

 

AstikThombare_1-1729012893884.png

 

If my reply helped with your issue please mark helpful 👍and correct ✔️if your issue is resolved.

 

By doing so you help other community members find resolved questions which may relate to an issue they're having

 

Thanks,

Astik

Brad Bowman
Kilo Patron
Kilo Patron

You can try adding ri.autoSysFields(false) before the update.  I hope this doesn't work - kind of undermines the validity of Updated by being a system field.

Hi @Brad Bowman  ,

 

Even after using autoSysFields(false) . It is taking updated by as current logged in user 

 

Thanks,

Astik