- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 01:41 AM
Hi All,
OncellEdit client script is not working, please tell me the issue in the below code
I have to use g_form.getReference call back function to populate user email
u_name is reference filed refering to USER table
u_email is string filed, onCellEdit of Name(refernce) filed I have to populate user's email in the email string filed
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
alert("test on cell edit");
if (newValue != oldValues) {
var userEmail = g_form.getReference('u_name', populateEmail);
alert(userEmail.email);
saveAndClose = true;
} else {
saveAndClose = false;
}
function populateEmail(userEmail) {
g_form.setValue('u_email', userEmail.email);
}
callback(saveAndClose);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 02:56 AM
Hi,
what type of BR is this? if this is before update then remove current.update()
Also do you want it to set when u_name changes or you want to set u_email always
if always then use this
current.u_email= current.u_name.email;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 01:50 AM
Hi Shantarao,
g_form will not work from list. You can use a onChange() client script or a before update business rule to update the field. Something as below
if (current.u_name.changes()){
current.u_email= current.u_name.email;
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 02:28 AM
Hi Jaspal,
I tried before business rule, but it is not working as expected, any other suggesions please
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 02:37 AM
Hi,
Can you share the Business rule script?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 02:42 AM
Hi Bawiskar,
Please find the code below
if (current.u_name.changes()){
current.u_email= current.u_name.email;
current.update();
}