The CreatorCon Call for Content is officially open! Get started here.

getting null value in client script

jack33
Tera Expert

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'
});

 

2 ACCEPTED SOLUTIONS

U_Viswa
Mega Sage

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

View solution in original post

Thank you Viswa, it worked

View solution in original post

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

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';

 

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  

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?

U_Viswa
Mega Sage

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