- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 12:38 AM
Hi Team,
I wonder why the auto-populate field is not working in portal view but working in technical view.
Hence im trying to create a onchange script to get the phone territory but its not working any idea how can I achieve this ?.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('who_is_this_request_for', function(user) {
if (user.location) {
g_form.getReference(user.location, function(location) {
if (location.parent) {
g_form.getReference(location.parent, function(parentLocation) {
if (parentLocation.phone_territory) {
g_form.getReference(parentLocation.phone_territory, function(phoneTerritory) {
var ccc = phoneTerritory.ccc
var displayValue = '+' + ccc;
g_form.setValue('phone_number', displayValue);
});
}
});
}
});
}
});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:01 AM
it clearly means the user doesn't have read access to that referenced table and hence cannot bring the data.
you are doing multiple getReference with callback which is not good at client side.
Please use normal onChange + GlideAjax and use GlideRecord and see if that works fine.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:05 AM
Hi @Jeck Manalo
Looks like the user doesn't have access for that table.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:05 AM
Hi @Jeck Manalo
Looks like the user doesn't have access for that table.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:01 AM
it clearly means the user doesn't have read access to that referenced table and hence cannot bring the data.
you are doing multiple getReference with callback which is not good at client side.
Please use normal onChange + GlideAjax and use GlideRecord and see if that works fine.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2025 02:06 AM
try this
Script Include: Client callable
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPhoneNumber: function() {
var userId = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
if (user.get(userId)) {
var location = new GlideRecord('cmn_location');
if (location.get(user.location)) {
var parentLocation = new GlideRecord('cmn_location');
if (parentLocation.get(location.parent)) {
var phoneTerritory = new GlideRecord('cmn_location');
if (phoneTerritory.get(parentLocation.phone_territory)) {
return '+' + phoneTerritory.ccc;
}
}
}
}
return '';
},
type: 'GetUserDetails'
});
onChange client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('phone_number');
if (oldValue != newValue) {
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getPhoneNumber');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(response) {
if (response != '') {
g_form.setValue('phone_number', response);
}
});
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader