getting the user's email

sonita
Giga Guru

On my form I have a field that shows the requester's email address when the form loads:

find_real_file.png

in order to get this done , on the default value of the filed i have :

find_real_file.png

Now , on the form, if someone selects yes in (Is this on behalf of someone else?) , in the ( on behalf of) they can select another user. so if this happens , i need the user's email address pop up in another field. what is the easiest way to achieve this?

find_real_file.png

1 ACCEPTED SOLUTION

function onChange(control, oldValue, newValue, isLoading) {



    alert("Value of   on_behalf_ref is: "+ on_behalf_ref);


  var usr= g_form.getReference('on_behalf_ref', doAlert);


}


function doAlert(usr) {



  if (usr.email != '')


      alert("email is: " + usr.email);


    g_form.setValue('requested_for', usr.email);


}


Can you try this, and tell me what are the alert messages (there should be 2 messages).


View solution in original post

13 REPLIES 13

this is the UI policy:



find_real_file.png


find_real_file.png


the problem is that the on behalf of field is part of a variable set that we use for allll the forms and when YES is selected it will auto populate the gs.user and   the email is also for gs. user , when I change the name to something else , it doesn't work!


Hey Soni,


I think you are putting the script at a wrong place. It should be a OnChange   Client script, which works when you change the field "on_behalf_ref". AND For UI Policy, your condition is correct, but did you add UI Policy Action? Add UI Policy action under that UI Policy. Make "Requestor's email address" Visible = true. Check the screenshot below:


find_real_file.png


Here you go. Just change the name of variables (i have highlighted it). This works for me. Delete the default value of email, and then test this. Once this works well, create another onLoad client script of logged in user.


find_real_file.png


kiara1
Tera Expert

Hi Soni,



Best solution for this would be using an Onchange Client script when "On Behalf of" changes. Now for auto-populating the email   address, you can use any   of the following methods:


1) Short Method: You can use getReference method in your client script. Please check this wiki link: GlideForm (g form) - ServiceNow Wiki


2) Long Method: Create Script include to return email address, use GlideAjax in client script to call the script include. Check the examples in this link: GlideAjax - ServiceNow Wiki



Let me know if this works!



Thanks


Kunpriya