- 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:17 AM
Hi
Thanks for your reply.
I thought of doing that initially but as there are two reference fields here - language and country,
I was not to able to use values of these two variables together in my client script using glideAjax i.e language.id and country.iso3166_2.
If possible can we tell how I can use these two together.
Suppose we have both the values for language id and country id, how can add these values to get the resolution field value.
Regards,
Afsar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 06:39 AM
I could provide a working example, but can you tell me which is the table? I can't find the table that has both fields: country and language. Unless you need this in a Catalog Item, but in that case can you tell me what is the definition of the "Language" variable? I'm assuming, whatever the case, Country is a field or a variable that is a reference to core_country. Let us know if not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2022 07:08 AM
Hi,
Language field is referencing to sys_language table and Country field is referencing to core_country table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 12:23 AM
Open Control Panel > Uninstall a program.
Locate latest Microsoft Visual C++ (64bit) and click on Change (If you're using 64 bit version of Teams, maybe you need x86)
Click on Repair.
Enter your Admin credentials to perform repair.
Regards,
Rachel Gomez