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

Have you verified the state are correct? I just tested with one state on Incident, works immediately.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Or did you perhaps miss any fields on UI Action, for example didn't select Form Button? Can you share a screenshot?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Now it is printing the logs but it is printing the logs which are only before while loop. state and everything which I have given is correct only.

inputOla.addQuery('number', current.sys_id);

 

Number doesn't sound like a reference field? Though you are entering a sys_id to query. Can you verify that this is correct or that this is your mistake?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

yes number is not a reference field