- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 03:33 AM
Hi,
I have created one catalog item in the Resolution field is populating by concatenating first six fields.
It is working fine in the catalog view but when I am testing this catalog item in the portal side I am getting this error- "There is a JavaScript error in your browser console".
For this catalog item I have written 6 same onChange client scripts which I have mentioned below in this question.
I have also attached the catalog form as well as browser console error screenshot.
How can we fix this error?
The client script I have written is below-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
else
{
var lang=g_form.getReference('language');
var language=lang.id;
var ctry=g_form.getReference('country');
var country=ctry.iso3166_2;
var region=g_form.getValue('region');
var category=g_form.getValue('category');
var subcategory=g_form.getValue('subcategory');
var site=g_form.getValue('site');
var fieldArray=[];
fieldArray[0]=region;
fieldArray[1]=category;
fieldArray[2]= subcategory;
if(language==undefined)
{
g_form.addInfoMessage("inside if");
fieldArray[3]="not count";
}
else
{
g_form.addInfoMessage("inside else");
fieldArray[3]=language;
}
if(country==undefined)
{
fieldArray[4]="not count";
}
else
{
fieldArray[4]=country;
}
fieldArray[5]=site;
var i, count=0;
for(i=0;i<=5;i++)
{
if(fieldArray[i]!="not count" && fieldArray[i]!='')
{
count++;
}
}
g_form.addInfoMessage("value of count:" + count);
var resolutionArray=[count];
var k=0,j=0;
for(j=0;j<6;j++)
{
if(fieldArray[j]!="not count")
{
resolutionArray[k]=fieldArray[j];
k++;
}
}
g_form.addInfoMessage("value of k: " + k);
var result='';
var l=0;
for(l=0;l<count;l++)
{
if(l!=count-1)
{
result= result + resolutionArray[l] + "." ;
result=result.toLowerCase();
}
else
{
result= result + resolutionArray[l];
result=result.toLowerCase();
}
if(l==count-1)
{
g_form.setValue('resolution', result);
}
}
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 04:37 AM
Please try this below scripts
Client Script: Write this script on Language field (on change)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_language", newValue);
ga.addParam("sysparm_country",g_form.getValue('country'));
ga.getXML(getResponse);
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
var region=g_form.getValue('region');
var category=g_form.getValue('category');
var subcategory=g_form.getValue('subcategory');
var site=g_form.getValue('site');
g_form.setValue('resolution field back end name',region+'.'+category+'.'+subcategory+'.'+values[0]+'.'+values[1]+'.'+site);
}
}
Script include:
var getStandardFields = Class.create();
getStandardFields.prototype = {
getFields : function() {
var standardFields = new GlideRecord('your language table name');
standardFields.addQuery('sys_id', this.getParameter('sysparm_language'));
standardFields.query();
if(standardFields.next()) {
var country = new GlideRecord('your country table name');
country.addQuery('sys_id',this.getParameter('sysparm_country'))
country.query();
if(country.next())
{
return standardFields.id.toString()+'|'+country.iso3166_2.toString();
}
}
return '';
},
type: 'getStandardFields'
};
Please mark my answer correct if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 04:11 AM
Then i suggest you to use a glide ajax as get reference is not supported in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 04:20 AM
There are two reference field here Language and country.
How can we merge these two values together to get in the resolution field?
Suppose we have following values for all variables -
Region - na
Category - itsm
Subcategory- inc
Language - English
Country- India
Site- abc
then Resoultion field value would show - na.itsm.inc.en.in.abc
How to achieve this using glideAjax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 04:37 AM
Please try this below scripts
Client Script: Write this script on Language field (on change)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_language", newValue);
ga.addParam("sysparm_country",g_form.getValue('country'));
ga.getXML(getResponse);
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
var region=g_form.getValue('region');
var category=g_form.getValue('category');
var subcategory=g_form.getValue('subcategory');
var site=g_form.getValue('site');
g_form.setValue('resolution field back end name',region+'.'+category+'.'+subcategory+'.'+values[0]+'.'+values[1]+'.'+site);
}
}
Script include:
var getStandardFields = Class.create();
getStandardFields.prototype = {
getFields : function() {
var standardFields = new GlideRecord('your language table name');
standardFields.addQuery('sys_id', this.getParameter('sysparm_language'));
standardFields.query();
if(standardFields.next()) {
var country = new GlideRecord('your country table name');
country.addQuery('sys_id',this.getParameter('sysparm_country'))
country.query();
if(country.next())
{
return standardFields.id.toString()+'|'+country.iso3166_2.toString();
}
}
return '';
},
type: 'getStandardFields'
};
Please mark my answer correct if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 08:34 AM
Thanks a lot
After doing little modification it worked.
Thank you so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 04:10 AM
The synchronous form of g_form.getReference
is not supported in portal. Thus lang
ends up being undefined
. One needs to use the asynchronous form of g_form.getReference
, in which case a callback function is provided.
Though especially in the described case, where a cascade of g_form.getReference
is used, a way better option would be to replace all of it by a singe GlideAjax
call.