- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 05:31 AM
I am checking unique catalog item name in table sc_cat_item and always getting null
wrote onchange catalog client script on variable create_catalog_item and client callable SI
Here is the code
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cat_name = g_form.getValue('create_catalog_name');
alert('cat_name'+cat_name);
var ga = new GlideAjax('UniqueCatalogName');
ga.addParam('sysparm_name','getName');
ga.addParam('sysparm_cat_name',cat_name);
ga.getXML(getCatName);
function getCatName(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer'+answer); //getting null
if(answer == 'true'){
g_form.showErrorBox('create_catalog_name','This name is already available,please select other name');
g_form.clearValue('create_catalog_name');
}}}
Script include:
var UniqueCatalogName = Class.create();
UniqueCatalogName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getName: function(){
var cat_name = this.getParameter('sysparm_cat_name');
var trimed_name = cat_name.trim();
var flag = false;
gs.log('cat_name' + cat_name + ' trimed name' + trimed_name);
var avil_name = new GlideRecord('sc_cat_item');
avil_name.addEncodedQuery('name=' + cat_name + '^ORname=' + trimed_name);
avil_name.query();
if (avil_name.next()) {
flag = true;
} else {
flag = false;
}
return flag;
},
type: 'UniqueCatalogName'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 06:57 AM - edited ‎10-10-2022 06:57 AM
Hi Jack,
issue with your scriptinclude function name "getName" change with something like "getNameOfCatalog".
This would fix your issue. Please let me know after trying.
Thanks
Viswa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2022 07:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 05:50 AM
Are you seeing the cat_name and trimed_name log from the SI? With the cat_name you are using for testing, are you expecting a true value to be returned? Change your flag values to strings so that a string value is returned to the Client Script. And you don't need the else block since the value will already be false.
var flag = 'false';
...
flag = 'true';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 06:27 AM
Yes I am getting value of cat_name and trimed_name, I'm accepting true if catalog item name is already available and false if unique name entered in variable.
By changing flag value to string also it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 06:48 AM
If you log flag in the SI before the return to confirm the value returned to the client is 'true' or 'false' then your alert on answer is still null?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 06:57 AM - edited ‎10-10-2022 06:57 AM
Hi Jack,
issue with your scriptinclude function name "getName" change with something like "getNameOfCatalog".
This would fix your issue. Please let me know after trying.
Thanks
Viswa