- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 09:01 AM
Hello,
I have a country variable in a request item which is automatically filled thanks to the country of the location (location which is another variable in the same request item).
When location is filled, country is automatically filled.
This works thanks to a catalog client script. It only works on the platform but not in the portal.
I know that g_form.getReference can’t be used in catalog client script and so we need to create a callback function.
I created it but I still have the problem : ok on the platform but not in the portal.
Here is the catalog script I wrote:
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('user_location', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
g_form.setValue('user_country',caller.country);
}
Do you have any idea why it is not working in the portal ?
Thanks
Vanessa Heux
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2019 05:34 AM
if above solution not working , replace the code with script include + glide ajax .
try now with below sample code.
Sample Code:
Script Include:
var getCountry = Class.create();
getCountry.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCont : function(){
var cnt = this.getParameter('sysparm_user_name');
var gr = new GlideRecord('cmn_location');
gr.get(cnt);
var cmn = new GlideRecord('core_country');
cmn.addQuery('name',gr.country.getDisplayValue());
cmn.query();
if(cmn.next()){
return cmn.sys_id;
}},
type: 'getCountry'
});
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var caller = g_form.getValue('user_location'); // make sure about the variable name
var ga = new GlideAjax('getCountry');
ga.addParam('sysparm_name', 'getCont');
ga.addParam('sysparm_user_name',caller);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('user_country',answer); // make sure about the variable name
}
}
Note: Validate the variable name in above client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2019 05:28 AM
This attempt does not work neither.
It seems to be so easy but it still does not work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2019 01:05 AM
The setDsiplayValue does not work in the portal nor in the platform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2019 12:44 AM
I'm not sure that getReference is supported at all on the service portal, regardless of whether you use a callback function or not. GlideAjax is the standard go to solution for making calls from client side scripts to server side script includes and returning data that way, there's plenty of documentation and community articles on how to write that.
You might also want to check our Michael Ritchie's getReferenceAdvanced() solution. you have to download it from Share but it's basically a UI script that you can call from any client script that makes a REST call back into the instance to get the data you need, you can read more here

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2019 12:47 AM
just want to add here,
if you are using getReference () with call back function then it will work on portal .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2019 12:50 AM
In catalog client scripts add below code for your requirment
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var user = g_form.getReference('requested', autoFill); //requested is reference feild
function autoFill(user) {
var gr = new GlideRecord('cmn_location'); // have to make a new gr object to get dept info
gr.addQuery('id', gr.get(user.location));
gr.query(function(gr) {
gr.next();
g_form.setValue('Location feild',gr.name);
});
alert("Location Name"+gr.name);
}
}