Relative date on a UI Action condition

mark_oldroyd
Tera Contributor

Hi,

 

I need to add a condition on a UI Action button to only show it for cases that were resolved more than 7 days ago.

Struggling with the correct syntax, can anyone help?

Thanks!

1 ACCEPTED SOLUTION

abhi159
Kilo Sage

use this  condition - current.resolved_at && current.resolved_at <= gs.daysAgo(7)

this will applicable on records which resolved on 7 days  ago or more than that

 

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

View solution in original post

3 REPLIES 3

Aniket Chavan
Tera Sage
Tera Sage

Hello @mark_oldroyd ,

 

You can update your UI Action condition with the following code, which I’ve tested in my PDI, and it worked as expected:

 

(current.resolved_at && gs.daysAgo(current.resolved_at) > 7)


Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket

 

abhi159
Kilo Sage

use this  condition - current.resolved_at && current.resolved_at <= gs.daysAgo(7)

this will applicable on records which resolved on 7 days  ago or more than that

 

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

Mark Manders
Mega Patron

You can't directly put this in you condition field. And assuming you don't want to create a field on the table just for a ui action to show or not, you will need to create a script include and call that from your ui action.

 

Check if below will work for you:

 

var CheckResolvedDate = Class.create();
CheckResolvedDate.prototype = {
    initialize: function() {},
    isResolvedMoreThanSevenDaysAgo: function(recordSysId) {
        var gr = new GlideRecord('sn_customerservice_case'); 
        if (gr.get(recordSysId)) {
            if (!gr.resolved_at) {
                return false;
            }
            
            var resolvedAt = new GlideDateTime(gr.resolved_at);
            var sevenDaysAgo = new GlideDateTime();
            sevenDaysAgo.addDaysUTC(-7);

            return resolvedAt.before(sevenDaysAgo);
        }
        return false;
    },
    
    type: 'CheckResolvedDate'
};

and call it like "CheckResolvedDate.isResolvedMoreThanSevenDaysAgo(current.sys_id)"
"


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark