- 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 07:03 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 08:03 AM
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
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-11-2020 05:36 AM
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
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:56 AM
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2020 05:09 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader