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.

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

I wrote this , it gave me this error:



find_real_file.png


this approach again shoes the email of the logged in user


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).


Working as expected. Thanks


Hi Soni,


Try this:


1) delete the default value of email address field (for this we can use onload client script). Try Onchange script now.


2) If the field hide/show issue still exist, can you comment that part of the code and use UI Policy.



Please let me know if the solution works!



Thanks


Kunpriya