
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-10-2021 08:36 PM
We often come across scenarios where we have to put condition in UI Action which cannot be written with a simple condition. e.g. current.active == true or current.canRead() etc, etc.
People often get confused to use advance condition in UI action. Yes, the very common mistake we do is we put javaScript: in UI action condition. Like advanced reference qualifier or filter condions etc, we need not put javaScript: when we are calling a script include from UI action. Moreover, the script include should return true/false as well.
Advanced condtion in a UI action will look like the following snapshot:
For example: we are asked to show a UI action when a incident is closed and it should have been closed in last 30 days.
Below is the script include and if you notice the above condition there is no javaScript: there:
getCondition: function(currentObj) {
// If state is not closed, then directly return false
if (currentObj.state != 3) {
return false;
}
// otherwise, compare closed date is within last 30 days
var nowDateTime = new GlideDateTime();
var dur = new GlideDateTime();
nowDateTime.setDisplayValue(gs.nowDateTime());
var closedDateTime = currentObj.closed_at.getDisplayValue();
dur = gs.dateDiff(closedDateTime, nowDateTime);
var dateDifference = new GlideDuration(dur);
var d = dateDifference.getDayPart();
if (d <= 30) {
return true;
}
return false;
},
- 3,838 Views