- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 04:41 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:16 AM
Hi @Community Alums ,
U can do something like this,
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:19 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:24 AM
Hi @Community Alums are you storing Onhold date in the table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 05:27 AM
Yes I have created an On-hold date field in incident and storing there.