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.

Widget get user name and user id

hurm
Tera Contributor

I want get the current user name and user id ,display in the preview

plase help me 

thanks

 

find_real_file.png

1 ACCEPTED SOLUTION

Hi zhian,

If you look at the screenshot that I posted earlier the fields that are references have two correlating properties. One property displays the sys_id of the referenced record and the other one displays the display value of the record. It's indicated by the suffix of "_dv" at the end of the property name.

So to show the display value of the department it would be user.department_dv instead of user.department.

find_real_file.png

View solution in original post

21 REPLIES 21

hurm
Tera Contributor

 I succeeded, thank you

Pavankumar_1
Mega Patron

Hi,

You can try below scripts:

HTML Template:

<div class="button-box">
<!-- your widget template -->
  
   <p>User name : {{data.username}}</p>
   <p>User ID : {{data.userid}} </p>
    <p>User Email : {{data.mail}} </p>
  </div>

Server Script:

(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */

    data.username = gs.getUser().name;
    data.userid = gs.getUser().getDisplayName();
     data.mail = gs.getUser().email;

})();

 

Result:

find_real_file.png

 

 

You can add background colors and other styling as per requirement.

Hope it helps!!

Please Mark Correct/Helpful, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

This was helpful.
Thank you very much.

Hi,

Good to hear!

Please Mark Correct/Helpful, Thanks!! 

 

Regards

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

thank you for your help