How to Hide a Button in incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 03:14 AM
Hello All,
I created a button called "Reminder" in incident form.
Need to hide that button for current Assignment group members.
It should be visible for one of Previous assignment group members.
if
1. State is assigned
2.Assignment group is not Empty
3.Assigned to is Empty.
4.Updated time is >5hours.
and button should be visible within Business hours of currently Assigned group.(we have field called business time left).
Please suggest how should we achieve this.
Thanks,
Abdul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 08:33 AM
Hi Abdul333,
You can create a script include containing the desired logic, that returns True or False, and reference that in the UI Action Condition field. A test script include:
UI Action that uses the script include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 02:38 PM - edited 08-06-2023 04:01 PM
Hi,
I took a stab at script logic for your requirements. Most are covered here, you can add more code. I don't understand
"It should be visible for one of Previous assignment group members." what is Previous assignment group members?
var HideButtonLogic = Class.create();
HideButtonLogic.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isVisible: function(curRecord, userID) {
gs.info("The user is " + userID);
//Need to hide that button for current Assignment group members.
//
// It should be visible for one of Previous assignment group members.
//if
// Requirement 1 (note: there is no choice for 'state' is "assigned" OOB)
var stateIsAssigned = true;
// if (curRecord.state != [value for 'Assigned']) // use proper value
// stateIsAssigned = false;
// REquirement 2 - Assignment group is not Empty
var assignmentGroupEmpty = false;
if (curRecord.assignment_group == '')
assignmentGroupEmpty = true;
// Requirement 3 - Assigned to is empty
var assignedToEmpty = false;
if (curRecord.assigned_to == '')
assignedToEmpty = true;
// Requirement 4 partial - check if user is a member of assignment_group
var isGrpMember = false;
var sugm = new GlideRecord('sys_user_grmember');
sugm.addQuery('group', curRecord.assignment_group);
sugm.addQeury('user', userID);
sugm.query();
if (sugm.next()) {
isGrpMember = true;
}
// Remaining Requirement 4 - something about update time being in Business hours
// TBD
// Now check conditions
if (isGrpMember)
return false;
if (!assignmentGroupEmpty && assignedToEmpty && stateIsAssigned)
return false; // button is not shown
else
return true;
},
type: 'HideButtonLogic'
});
And the condition on the UI action needs to change to:
new HideButtonLogic().isVisible(current, gs.getUserID());
as the current user is needed.