How to do onChange in Service Portal widget

Bruler1230
Tera Expert

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

 

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Below solution will be helpful to you

 

https://community.servicenow.com/community?id=community_question&sys_id=dd6702aedb59d300fac7f4621f96190d

 

Regards,

Sachin

rajneeshbaranwa
Giga Guru

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.

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

Vinod Kondagad1
Tera Contributor

Can you share full code here