workspace in servicenow

shrngikaG
Tera Contributor

how to populate loggedin user name in servicenow workspace.

don't have any idea about workspace.

1 ACCEPTED SOLUTION

Sarthak Kashyap
Tera Expert

Hi @shrngikaG ,

I tried your problem in my PDI and it works for me please check below solution 

1. Create client script and add below code 

function handler({
    api,
    event,
    helpers,
    imports
}) {
    var name = api.context.session.user.fullName;
    api.setState('loggedInuser', name);
}

SarthakKashyap_0-1735624662268.png

 

2. Create client state parameter 

SarthakKashyap_1-1735624729627.png

 

3. Add this client state parameter to stylized text or where ever you want to show the current user name 

SarthakKashyap_2-1735624832127.png

 

Result 

SarthakKashyap_3-1735624863086.png

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

 

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@shrngikaG 

where to populate?

in which field?

please share some screenshots.

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

Thank you ! I used Sarthak solution it's working.

Sarthak Kashyap
Tera Expert

Hi @shrngikaG ,

I tried your problem in my PDI and it works for me please check below solution 

1. Create client script and add below code 

function handler({
    api,
    event,
    helpers,
    imports
}) {
    var name = api.context.session.user.fullName;
    api.setState('loggedInuser', name);
}

SarthakKashyap_0-1735624662268.png

 

2. Create client state parameter 

SarthakKashyap_1-1735624729627.png

 

3. Add this client state parameter to stylized text or where ever you want to show the current user name 

SarthakKashyap_2-1735624832127.png

 

Result 

SarthakKashyap_3-1735624863086.png

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

 

Runjay Patel
Giga Sage

Hi @shrngikaG ,

 

Write client script on table, it will impact on workspace as well.

For example if you wanna set caller as logged in user for incident table then you need to write onload client script on incident table. Use below script to set the value.

    g_form.setValue('caller_id', g_user.userID);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------