How to hide suspend ,skip, cancel RITM button on sc_task table for specific catalog item without DOM manipulation in serti

diwakarsingh
Tera Expert

How to hide suspend ,skip, cancel RITM button on sc_task table for specific catalog item without DOM manipulation in service now

 

Currently they have been hidden using below script-

 



var itemID = g_form.getParameter("sysparm_id");
if (itemID == g_scratchpad.salesInvoiceItemID) {
var buttons = document.getElementsByClassName("form_action_button action_context btn btn-default");
for (var i = 0; i < buttons.length; i++) {
switch (buttons[i].id) {
case "sysverb_update_and_stay":
if (g_form.getValue("assigned_to") == "" || g_form.getValue("assigned_to") != g_user.userID) {
buttons[i].hide();
} else {
buttons[i].show();
}
break;
case "ukotvassigntome":
buttons[i].show();
break;
case "uksalesledger_reassign":
buttons[i].show();
break;
case "salesinvoicecomplete":
buttons[i].show();
break;
default:
buttons[i].hide();
}
}
}
}

4 REPLIES 4

Ravi9
ServiceNow Employee
ServiceNow Employee
Can I ask why they did it this way? Were they not able to build normal condition in those ui action?

I don't know this was developed by other developer now in health scan these are brought up so need to fix them . 

Ravi9
ServiceNow Employee
ServiceNow Employee

ok ! then why dont you try building a condition on ui action and see if you stuck somewhere , we can work from there ! 

Hi Ravi,

 

I tried below 

SalesbuttonCheck: function(sourceRec, actionName) {
var allowAction = false;
if (gs.hasRole('admin')) {
allowAction = true;
return allowAction;
}
if (!gs.getUser().isMemberOf(sourceRec.assignment_group))
return allowAction;
switch (actionName.toString()) {

case "cancel_request":
if ((sourceRec.state == 1 || sourceRec.state == 2) && sourceRec.request_item.cat_item.sys_id != gs.getProperty('salesInvoiceCatSysID')) {
allowAction = true;
}
break;
// case "suspend":
// if ((sourceRec.state == 1 || sourceRec.state == 2) && (sourceRec.request_item.cat_item.sys_id != gs.getProperty('persist.cp.item_sys_id')) {
// allowAction = true;
// }
// break;
case "skip":
if ((sourceRec.state == 1 || sourceRec.state == -5 || sourceRec.state == 2) && sourceRec.request_item.cat_item.sys_id != gs.getProperty('salesInvoiceCatSysID')) {
allowAction = true;
}
break;

}
return allowAction;
},

and then called in UI action condition but it is not working