How to do onChange in Service Portal widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 08:22 AM
Hello,
Currently, users can have multiple email addresses associated with their servicenow profile, and only one can be their preferred email address. I am trying to add a dropdown select box to the service portal user profile widget that will allow users to change their preferred email address from the service portal. I have the dropdown created, and i am able to populate the drodpown with users email addresses. The thing i cant figure out is how to make the change. When a user chooses a different email, how do i make the change to the user record? I know how to do this on the platform side, but cant figure out how to do this in service portal. Is there something in the client script that i need to do? I am using the OOTB user profile widget.
I can give the code i have so far if needed.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 08:27 AM
Below solution will be helpful to you
https://community.servicenow.com/community?id=community_question&sys_id=dd6702aedb59d300fac7f4621f96190d
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 09:03 AM
Can you share the code ? In your dropdown , you need to call client controller function on ng-change which will send an input and input.action to server side and server script will update the email address.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 01:00 PM
Thanks..here are the changes i made. Right now, this populates the drodown with the email addresses in the u_emails field. But how do i update the profile when a user picks a new email address from the list to be the main email?
HTML:
<div>
<div class="list-group-item">
<select
ng-model="data.listProperties.emails.current"
ng-change="setPreferenceValue('emails', data.listProperties.emails.current.value)"
ng-options="item for item in c.data.choices"
class="form-control"
/>
</div>
And added this to the server script:
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID().toString());
data.choices = gr.getValue('u_emails').split(',');
console.log("emails: " + data.choices);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2022 11:32 PM
Can you share full code here