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

Hi Bawiskar,

- ABC is my parent table

- HYZ is my embeded list table

- After selecting "u_name" fileds in the embeded list I want populate "u_email" from the user selected in the "u_name" field

- After adding the records on the XYZ embeded list table, I will save the Parent table "ABC"

sorry : I am not able to provide screenshot,

 

Hi Shantharao,

for screenshot that is fine;

So when u_name field selected in embedded list you want to populate u_email from u_name field

you need to have after update BR on embedded list table; and it will only trigger when you save the parent form

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi,

Is there any update on this? Is this question resolved or you need some more assistance.

Please consider marking appropriate reply as Correct & 👍Helpful.

Regards
Ankur

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

Ct111
Giga Sage

What you are trying to achieve doesnt meets the requirement of onCellEdit , it is mainly used for making changes to List view .

 

For example refer the below link

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

 

 

And for populating the email I would say refer the below Client Script and Script Include

 

Client Script

---------------------------

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}


var uid = newValue;

g_form.addInfoMessage(uid);

var ga = new GlideAjax('UserInfo');
ga.addParam('sysparm_name','getUserInfo');
ga.addParam('sysparm_usr',uid);

g_form.addInfoMessage('Hurray');

ga.getXML(test);


function test(response){


var user = response.responseXML.documentElement.getAttribute("answer");

user = JSON.parse(user);

if(user != null)
{

g_form.setValue('email',user.email);

}


}

}

 

Script Include.

 

var UserInfo = Class.create();
UserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getUserInfo:function()

{

gs.log('Inside Script Include');

var obj = {};

var user = this.getParameter('sysparm_usr');



var gu = new GlideRecord('sys_user');
gu.addQuery('sys_id',user);
gu.query();

if(gu.next())
{


obj.email = gu.getValue('email');


}

var str = JSON.stringify(obj);

return str;


},

type: 'UserInfo'
});

 

Mark my ANSWER as CORRECT and HELPFUL if it helps

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Is there any update on this? Is this question resolved or you need some more assistance.

Please consider marking appropriate reply as Correct & 👍Helpful.

Regards
Ankur

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