getting user name with mailscript?

sorcerermjolnir
Kilo Explorer

Hi everyone

So I've been trying with out much luck to get an automatic signature appearing in emails sent from the in built service now email client.

I've been using Client Templates to set the template for the incident table and while I can use a mail script to add in text I can't seem to get values from the g_user object.

The code I have in the template just now.

Kind regards,

<mail_script>

  template.print(g_user.userName);

</mail_script>

When opening the client I simply see the following:

Screenshot 2017-07-12 22.16.23.png

I've put in a string value to the template.print call and that prints out OK so I'm lead to believe that g_user simply isn't returning a value.

Is anyone able to help me shed some light on why g_user is not returning a value or should I be using a different method to retrieve the current user?

Kind regards,

Robert

1 ACCEPTED SOLUTION

chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Robert,



Try below script:


<mail_script>


template.print( gs.getUser().getFullName() );


</mail_script>


View solution in original post

4 REPLIES 4

chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Robert,



Try below script:


<mail_script>


template.print( gs.getUser().getFullName() );


</mail_script>


Shishir Srivast
Mega Sage

Can you please try with : gs.getUserName();


sorcerermjolnir
Kilo Explorer

Hi Shishir



That worked. not sure why as I'd tried that before and simply got 'undefined' as an output.


It's working this time though



Thank you very much,


Robert


Hi Robert,


g_user objects are client side user objects whereas mail script is server side. To get user values, we have to leverage gs.getUserID, and other server side user objects. thats the reason, your script did not return a value



Hope this was informative