Show UI Action only if the task has an active approval

dagarson
Tera Guru

Hello I am having an issue with a ui action condition I am trying to work on. the UI Action should only show when The task has an active approval record tied to it. however when I try to add my function from my script include the button never shows. I believe my logic is correct but I'm not seeing any issues.

 

Here is my script include script( client callable checked)

var ApprovalChecker = Class.create();
ApprovalChecker.prototype = {
    initialize: function() {},

    hasApprovals: function(recordSysId) {
        var approval = new GlideRecord('sysapproval_approver');
        approval.addQuery('document_id', recordSysId);
		approval.addQuery('state', 'requested');
        approval.query();
        return approval.hasNext(); // Returns true if there are any approvals, false otherwise
    },

    type: 'ApprovalChecker'
};

 

And here is the condition of the ui action

Screenshot 2024-07-03 130000.png

 

Any assistance would be helpful.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Looking at your condition, you are providing current as input? Though you are not using current in your Script Include? Shouldn't you provide current.getUniqueValue() or current.sys_id as input?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

View solution in original post

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Did you try adding any debugging? For example is the recordSysId valid and what you would expect? Is the return returning what you would expect? Or is the script perhaps failing?

 

Adding debugging could help show the issue within a few seconds.

 

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

Looking at your condition, you are providing current as input? Though you are not using current in your Script Include? Shouldn't you provide current.getUniqueValue() or current.sys_id as input?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

You are correct. I didnt even notice I had done that . changing it to current.sys_id did the trick thank you.

Mark Roethof
Tera Patron
Tera Patron

Just verified on a PDI, indeed the input you are providing is at least an issue. Change it as I mentioned in my previous reply.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn