OnCellEdit client script is not working?

Shantharao
Kilo Sage

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

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Jaspal Singh
Mega Patron
Mega Patron

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

Hi Jaspal,

 

I tried before business rule, but it is not working as expected, any other suggesions please

Thanks

Hi,

Can you share the Business rule script?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi  Bawiskar,

Please find the code below

if (current.u_name.changes()){
  current.u_email= current.u_name.email;
  current.update();
}