Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideRecord code is not working in Client callable UI action

Madhusagar Pal1
Tera Expert

Hi All, 

 

Need help/Suggestion

 

The query is when I click on the UI action, the condition need to check no product assigned is false, get the display of the parent , based on the parent display value need to populate number from the cmdb_ci_service_business table. 

The below code is populating the alert display name but not populating the number.

When I use the same code in back ground script it is working, please let me why it is not working in the UI action client callable.

 

if (noProductAssigned === "false") {
        var digitalProduct = g_form.getDisplayBox('parent').value;
       alert("digital product value in form: " + digitalProduct);   
        var digiProd = new GlideRecord('cmdb_ci_service_business');
        digiProd.addQuery('name', digitalProduct);
        digiProd.query();
        while (digiProd.next()) {
            var digitalProductNum = digiProd.getValue('number');
        }
        alert("digital product number is : " + digitalProductNum);
    
    }
 
Thanks & Regards,
Madhu.
1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage

Hi @Madhusagar Pal1 ,

 

If u have checked the client checkbox on the UI action then GlideRecord won't work as the UI action will behave like a client script. U can call a script include from the UI action using GlideAjax to perform that operation. This is one way.

 

Else what u can do is uncheck the checkbox for client,this way ur UI action will behave as a server side script n then u can do something like below.

 

if (current.noProductAssigned === "false") {

        var digitalProduct = current.parent.getDisplayValue();

       //alert("digital product value in form: " + digitalProduct); 

 

 //instead of alert u can use gs.info n try to print the logs

        var digiProd = new GlideRecord('cmdb_ci_service_business');

        digiProd.addQuery('name', digitalProduct);

        digiProd.query();

        while (digiProd.next()) {

            var digitalProductNum = digiProd.getValue('number');

        }

        //alert("digital product number is : " + digitalProductNum);

 

//Use gs.info to print logs as it's a server side script now. Alert can only be used at client side.

    

    }

 

Thanks,

Danish

 

View solution in original post

8 REPLIES 8

Danish Bhairag2
Tera Sage

Hi @Madhusagar Pal1 ,

 

If u have checked the client checkbox on the UI action then GlideRecord won't work as the UI action will behave like a client script. U can call a script include from the UI action using GlideAjax to perform that operation. This is one way.

 

Else what u can do is uncheck the checkbox for client,this way ur UI action will behave as a server side script n then u can do something like below.

 

if (current.noProductAssigned === "false") {

        var digitalProduct = current.parent.getDisplayValue();

       //alert("digital product value in form: " + digitalProduct); 

 

 //instead of alert u can use gs.info n try to print the logs

        var digiProd = new GlideRecord('cmdb_ci_service_business');

        digiProd.addQuery('name', digitalProduct);

        digiProd.query();

        while (digiProd.next()) {

            var digitalProductNum = digiProd.getValue('number');

        }

        //alert("digital product number is : " + digitalProductNum);

 

//Use gs.info to print logs as it's a server side script now. Alert can only be used at client side.

    

    }

 

Thanks,

Danish

 

Hi Dinesh,

 

As you recommended, i tried using GlideAjax but still not working, Please check the below code and let me know.

 

Client Side:

if (noProductAssigned === "true") {
        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_prodGroup', productGroup); //Parameters
        ga.getXML(getResponse);

        function getResponse(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");
            alert("Response from the script include:" + answer);  --> this line is working and popup the number in the form
            var productGroupID = answer;
            gs.info("productGroupID from the script include:" + productGroupID);  --> it is not working
              }
    }

 

Server Side(script include):

var getProductGroupID = Class.create();
getProductGroupID.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getProdGrpID: function() {

        var product_group = this.getParameter('sysparm_prodGroup');
        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'
});

 

Please suggest me where i did wrong.

 

Thanks & Regards,

Madhu.

Hi @Madhusagar Pal1 

 

Do you get an array of Product IDs as a response from the script include or it a single product ID ? I can see you have made use of a while loop in the script include to iterate over the spm_taxonomy_node table ?

 

Thanks & Regards

Amit Verma


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

single product group ID