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

Mihir Mohanta
Kilo Sage

Write a on change client script.



Use getReference() function there to get user's email.



Please follow below link for your reference.



GlideForm (g form) - ServiceNow Wiki




Thanks,


Mihir


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




  function doAlert(usr) { //reference is passed into callback as first arguments



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


}



doesn't work!!


Hi Soni,


Try this -


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


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


}


function doAlert(usr) {


  if (usr != '')


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


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


}


Another problem with this client script that I have is that even if the field (Is this on behalf of someone else?) is selected as No , the on behalf of field is shown. But the On behalf of the field should only be visible when yes is selected. but when i wrote the client script those fields are visible but they shouldn't.


and the functionality is not working either


find_real_file.png