Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How do get the field (when user update the state as pending) updated by name in notification

raj99918
Tera Contributor

Hi 

 

I have requirement like whoever changing the field called state(field is on sc_req_item table) as pending then notification should trigger with that state field upated by name in the body of the notification(on sc_req_item). How can I get this one

1 ACCEPTED SOLUTION

@raj99918 

you will have to use email script for that. I hope you know how to do that or can search in docs for the same

1) create email script -> get_user

2) then include that in email body of your notification like this and print the content

${mail_script:get_user}

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var gr = new GlideRecord("sys_user");
    gr.addQuery("user_name", current.sys_updated_by);
    gr.query();
    if (gr.next()) {
        template.print("State pending Updated By : " + gr.getDisplayValue());
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

@raj99918 

you can use this in email body if the notification is on RITM table

State pending Updated By : ${sys_updated_by}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar Thanks alot it's working fine but need one last change now am getting the userid but how to get the full user name ?

@raj99918 

you will have to use email script for that. I hope you know how to do that or can search in docs for the same

1) create email script -> get_user

2) then include that in email body of your notification like this and print the content

${mail_script:get_user}

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var gr = new GlideRecord("sys_user");
    gr.addQuery("user_name", current.sys_updated_by);
    gr.query();
    if (gr.next()) {
        template.print("State pending Updated By : " + gr.getDisplayValue());
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rajesh Chopade1
Mega Sage

hi @raj99918 

You can use flow designer as suggested by Ankur or use business rule to trigger the email notification:

  • Create a Business Rule on table sc_req_item to Detect the Change in the State Field 
  • Condition state changes to "Pending"
  • Call notification from the BR script

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

Rajesh