UI action visiblity

Community Alums
Not applicable

Hi Folks, I have a requirement from the client when the incident state is on hold then I have to show the "Close" UI action after 30 days from when it was on-hold. can someone help me on what I have to write UI action condition?

1 ACCEPTED SOLUTION

Hi @Community Alums ,

 

If you already have the date available you can just use this much peice of code

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

    verifydate: function(date) {

        
        var gdt = new GlideDateTime(date);
        var nowTime = new GlideDateTime();
        var duration = GlideDateTime.subtract(nowTime, gdt);
        var days = duration.getDayPart();

        if (days >= 30) { // modify the condition as per your need this is if 30 days or more then close button will appear
			return true;
        }else{
			return false;
		}

    },

    type: 'checkDate'
};

 

pass the date in this condition on UI action

new checkDate().verifydate(current.on_hold_date); // kindly use proper backend name of the on hold date field

 

Please mark my answer helpful & solution accepted if it resolves your query.

 

Thanks,

Danish

View solution in original post

7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Community Alums ,

 

U can do something like this,

 

  1. Create a UI action  on incident table & under condition field give the below condition

 

new checkDate().verifydate(current.sys_id);

 

  • Now create a script include (i have created it in global scope) & copy paste the below code:

 

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

    verifydate: function(id) {

        var gr = new GlideRecord('sys_audit');
        gr.addEncodedQuery('documentkey=' + id + '^tablename=incident^fieldname=state^newvalue=3'); // on hold state for me is 3
        gr.query();
        if (gr.next()) {
            var date = gr.sys_created_on;
        }

        var gdt = new GlideDateTime(date);
        var nowTime = new GlideDateTime();
        var duration = GlideDateTime.subtract(nowTime, gdt);
        var days = duration.getDayPart();

        if (days >= 30) { // modify the condition as per your need this is if 30 days or more then close button will appear
			return true;
        }else{
			return false;
		}

    },

    type: 'checkDate'
};

 

 

It should work, I have tested it in my PDI it works. Kindly check the same.

 

Please mark my answer helpful & solution accepted if it resolves your query.

 

Thanks,

Danish

Hi @Community Alums ,

 

In order to test the above change the days in if condition of script include from 30 to 0 & update it. Put any 1 incident in your development environment to On hold & see whether the close UI action appears or not.

 

Thanks,

Danish

Eswar Chappa
Mega Sage
Mega Sage

Hi @Community Alums are you storing Onhold date in the table?

Community Alums
Not applicable

Yes I have created an On-hold date field in incident and storing there.