- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 10:25 AM
On my form I have a field that shows the requester's email address when the form loads:
in order to get this done , on the default value of the filed i have :
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?
Solved! Go to Solution.
- 8,256 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 11:09 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 11:31 AM
this is the UI policy:
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 11:41 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 11:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 10:38 AM
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