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

Then you should make use of if. You can alter it like :

 

 

if (tax_nod.next()) {
            var prdouctGroupID = tax_nod.getDisplayValue('u_product_group_id');
            gs.info('Product Group ID using name  :' + prdouctGroupID);
            return prdouctGroupID;
        }

 

 

About your problem, I assume that productGroupID is one of your catalog variable. If you want to set the value of the catalog variable, you should make use of 

 

g_form.setValue('productGroupID',answer);

 

 

Can you please check on this


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

Amit Verma
Kilo Patron
Kilo Patron

Hi @Madhusagar Pal1 

 

Are you getting any output from the alert you have kept ? alert("digital product value in form: " + digitalProduct); 

 

Thanks & Regards

Amit Verma


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

Yes, I am getting the display name of the parent.

Vishal Birajdar
Giga Sage

Hello @Madhusagar Pal1 

 

You can use client side as well as server side script in UI action.

 

You have to consider below points :

1.Action name should be there

2.Client is checked

3.onClick - function name

 

VishalBirajdar_0-1706595153399.png

 

 

For example, 

 

I have created one UI action on incident form 'Update cmdb' , when user clicks on button One pop will get displayed..& one record from alm_hardware will get updated.

 

Button :

VishalBirajdar_1-1706595308626.png

 

When user clicks button pop will get displayed.

VishalBirajdar_2-1706595337012.png

 

When user clicks on OK , record from Hardware table gets updated.

 

VishalBirajdar_3-1706595416262.png

 

 

Here is UI action script :

 

 

/*1.When user clicks on button below function will get executed*/
function clientUpdateCmdb() {
    var message = confirm("Confirm incident number=" + g_form.getValue('number'));
    /*1.1 Once user clicks on OK in pop up same UI action will get invoked using action name but this time only Server side code will run */
    if (message == true) {
        gsftSubmit(null, g_form.getFormElement(), 'update_cmdb');   //action name
    }
}

/*2. Server side code will run */
serverUpdate();

function serverUpdate(){
var gr = new GlideRecord('alm_hardware');
gr.addQuery('sys_id','00a96c0d3790200044e0bfc8bcbe5dc3');
gr.query();

if(gr.next()){

	gr.asset_tag = 'P123456789';
       gr.update();
}
}

 

 

 

**You can adjust your code accordingly and use condition field as per your need

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates