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.

Hide UI Action on the basis of certain conditons

Pratiksha Lang1
Kilo Sage

I want to hide UI action on the basis of certain condition. I have written script include and I am calling that script include in UI action condition. It is not going in script include, I am not getting logs as well. Can anyone please help as it is not working as expected.

 

Script include :

 

var smdrsOlaScoringCompleted = Class.create();
smdrsOlaScoringCompleted.prototype = {
    allowOlaScoring: function(current) {
        gs.info("@@@checking my script include");
        var inputOla = new GlideRecord('x_amspi_smdrs_app_input_ola');
        inputOla.addQuery('number', current.sys_id);
        inputOla.addQuery('active', 'true');
        gs.info("@@@checking my script include 1");
        inputOla.query();
        while (inputOla.next()) {
            gs.info("@@@checking my script include 2");
            if (inputOla.frequency == 'Daily') {
                gs.info("@@@checking my script include 3");
                inputOla.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^state=1^ORstate=2');
                 return "true";
            }
        }
    },

    type: 'smdrsOlaScoringCompleted'
};
 
 
 
UI Action :
PratikshaLang1_0-1703678557366.png

 

15 REPLIES 15

vipinmathew
Mega Guru

Hi @Pratiksha Lang1 

try to call this function from background script and see it the log is working or not.

 

instead of current pass the gliderecord object of a record 

 

OR 

 

I have some suggestion to your Script as well

 

Script Include 

 

var smdrsOlaScoringCompleted = Class.create();
smdrsOlaScoringCompleted.prototype = {
    allowOlaScoring: function(current) {
        gs.info("@@@checking my script include");
        var inputOla = new GlideRecord('x_amspi_smdrs_app_input_ola');
        inputOla.addQuery('number', current.sys_id);
        inputOla.addQuery('active''true');
        gs.info("@@@checking my script include 1");
        inputOla.query();
        while (inputOla.next()) {
            gs.info("@@@checking my script include 2");
            if (inputOla.frequency == 'Daily') {
                gs.info("@@@checking my script include 3");
                inputOla.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^state=1^ORstate=2');
                 return true;   //return Boolean 
            }
        }
    },

 

    type: 'smdrsOlaScoringCompleted'
};

 

 

In UI Action condition :

 

new smdrsOlaScoringCompleted().allowOlaScoring(current) 

 

 

above line is enough instead of " new smdrsOlaScoringCompleted().allowOlaScoring(current) == 'true' "

 

 

Thanks 

Vipin Mathew

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Script Include looks oke. Maybe it's the condition field and the usage or ||

 

Can you update this using:

current.isValidRecord() && (current.state == 1 || current.state == 8 || current.state == 19 || current.state == -7) && new smdrsOlaScoringCompleted().allowOlaScoring(current)

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

I just tested your Script Include = oke. So do look at the condition like I mentioned. When I test with a simple condition to just trigger the Script Include, works fine.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

it doesn't work, tried with your suggestion. it doesn't show the button itself when I do that.