UI action client side code is not working

Madhusagar Pal1
Tera Expert

Hi  All,

 

The query is when click on UI action button on the form, product group id needs get from spm_taxonomy_node table then send the product group id to another script include.

 

 
Script include to get product group id  from the below script
var getProductGroupID = Class.create();
getProductGroupID.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getProdGrpID: function() {

        var product_group = this.getParameter('sysparm_prodGroupName');
        gs.info("Product group sys id :" + product_group);

        var tax_nod = new GlideRecord('spm_taxonomy_node');
        tax_nod.addQuery('name', product_group);
        tax_nod.query();
        while (tax_nod.next()) {
            var prdouctGroupID = tax_nod.getDisplayValue('u_product_group_id');
            gs.info('Product Group ID using name  :' + prdouctGroupID);
            return prdouctGroupID;
        }
    },

    type: 'getProductGroupID'
});
 
Passing productGroupID to UI action client script. 
var productGroup = g_form.getDisplayBox('spm_taxonomy_node').value;
        alert("product group value in form: " + productGroup);
        //v_asset_ci_creation.addParam('sysparm_productGroup', productGroup);
   
        var ga = new GlideAjax('x_jj_integration.getProductGroupID'); //Scriptinclude
        ga.addParam('sysparm_name', 'getProdGrpID'); //Method
        ga.addParam('sysparm_prodGroupName', productGroup); //Parameters
        ga.getXMLAnswer(function(groupID) {
        if (groupID != null) {
            alert("Response from the script include:" + groupID);
            var productGroupID = groupID;
            alert("productGroupID from the script include:" + productGroupID);
            gs.log("productGroupID from the script include:" + productGroupID);
            v_asset_ci_creation.addParam('sysparm_productGroup', productGroupID);
        }  
       
    });
 
When i click on the UI action button i am able to get group id but when i passing same to another script include ,
var v_productGroup = this.getParameter('sysparm_productGroup');
     gs.info("v_productGroup : "+ v_productGroup);
i can see null value for the product group id.
 MadhusagarPal1_0-1706694975211.png

 

Please let me know why it is not working.

 
3 REPLIES 3

Jagadish Sanadi
Kilo Sage

Hello Madhusarar,

 

Looks like your client script is wrong.

I have give sample client script modify function name and parameters accordingly 

 

var gaLocation = new GlideAjax('getUserPropertiesAJAX');
gaLocation.addParam('sysparm_name', 'get_location');
gaLocation.addParam('sysparm_user', newValue);
gaLocation.getXMLAnswer(_handleResponse);
 
function _handleResponse(response) {
var answer = answer;
g_form.setValue('groudID', answer);
}

 

 

Please mark my answer helpful If I have helped you

Hi Jagadish,

 

Thanks for reply.

 

In my code I don't want to set the form value, I want to pass response to another script include variable.

 

Thanks & Regards,

Madhu.

 

Hi @Madhusagar Pal1 

 

Assuming you have another function inside the same script include to get the product group, you can make use of below catalog client script to call that function, pass the productGroupID variable to the function as a param and get the productgroup as a response. Please give this a try.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var productGroup = g_form.getDisplayBox('spm_taxonomy_node').value;
    alert("product group value in form: " + productGroup);

    var ga = new GlideAjax('x_jj_integration.getProductGroupID'); //Scriptinclude
    ga.addParam('sysparm_name', 'getProdGrpID'); //Method
    ga.addParam('sysparm_prodGroupName', productGroup); //Parameters
    ga.getXML(OutputParse);

    function OutputParse(response) {

        var productGroupID = response.responseXML.documentElement.getAttribute("answer");
        if (productGroupID != null) {
            alert("Response from the script include:" + productGroupID);
			
            // calling another function in the same script Include
            ga.addParam('sysparm_name', 'getProductGroup'); //Assuming you have a function getProductGroup in the same script include
            ga.addParam('sysparm_productGroup', productGroupID); //Parameters
            ga.getXML(OutParse);

            function OutParse(res) {
                var v_productGroup = res.responseXML.documentElement.getAttribute("answer");
                if (v_productGroup != null) {
                    alert("Response from the script include:" + v_productGroup);
                }
            }

        }
    }
}

 

If you face issues, request you to share your complete script include code to debug it further.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.