We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Update company on user record

Darlene York
Tera Contributor

On my catalog item I have a variable called add_company.  If that company is filled out, a team will get a task to update the name variable on the core_company table.  Once that task is closed, the requirement is to auto update the company variable on the sys_user record.

I think I need a script to do this since the company table is not on the sys_user table. 

Any assistance with this would be greatly appreciated.

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Darlene York 

 

Try it 

Create the Business Rule

  • Name: Update User Company from Catalog Task
  • Table: Catalog Task [sc_task]
  • Advanced: Checked
  • When: after
  • Update: Checked
  • Order: 100

Set the condition to ensure this only runs for your specific task and when it is closed.
State Changes to Closed Complete

AND

Short description Contains <your task description>

 

(function executeRule(current, previous /*null when async*/) {

   var ritmGR = new GlideRecord('sc_req_item');

    if (ritmGR.get(current.request_item)) {

      var companySysId = ritmGR.variables.add_company;

        if (companySysId && userSysId) {

            var userGR = new GlideRecord('sys_user');

            if (userGR.get(userSysId)) {

                userGR.company = companySysId;

                userGR.update();

                ritmGR.work_notes = "User " + userGR.name + " company updated to " + userGR.company.getDisplayValue();

                ritmGR.update();

            }

        }

    }

})(current, previous);

 

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

5 REPLIES 5

Thank you, I will give your solution a try.