- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 01:24 AM
Hi guys,
I have a requirement to show only Approved and Rejected in the State field of sysapproval_approver table.
So here, when the approver opens the form, he or she needs to see only the "Approved" and "Rejected" (and perhaps "Requested" as well). And this should be applied only to a specific catalog item.
Any ideas?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 02:06 AM
Let's try the approach below to hide Approval States on a specific Catalog Item.
1. Define an OnLoad Client Script
2. Call an Ajax script include to validate the catalog item by passing the associated RITM as param.
Sample below.
function onLoad() {
if (g_form.getValue('source_table') !== 'sc_req_item') {
return;
}
var ga = new GlideAjax('CLIncidentUtilsAJAX'); //your client callable script include
ga.addParam('sysparm_name', 'checkCatalogItem');
ga.addParam('sysparm_ritm_id', g_form.getValue('document_id'));
ga.getXMLAnswer(function(answer){
if(answer === 'true'){
g_form.removeOption('state', 'not requested');
g_form.removeOption('state', 'cancelled');
g_form.removeOption('state', 'not_required');
g_form.removeOption('state', 'more_info_required');
g_form.removeOption('state', 'duplicate');
}
});
}
3. Create an Ajax script include with the function named checkCatalogItem
4. Query to get the Requested item, then validate the Catalog Item
var CLIncidentUtilsAJAX = Class.create();
CLIncidentUtilsAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkCatalogItem: function(){
var grRITM = new GlideRecord('sc_req_item');
if(grRITM.get(this.getParameter('sysparm_ritm_id'))){
//you can store the catalog item sys_id in a system property to avoid hard-coding
return grRITM.getValue('cat_item') === 'e591f18b47eaf990ab9bb6bf016d430b'; //your catalog item sys_id
}
return false;
},
type: 'CLIncidentUtilsAJAX'
});
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 08:45 AM
Hi Timi,
I found out why the code did not work.
I has to do with the very first line indeed.
I changed it to the following and everything works fine:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 09:07 AM
You just need to replace HR related fields and table using the same approach as below.
Try with below solution.
1. Create Display business rule on sysapproval_approver table (check advanced check box).
2. In when to run for this business rule, add two conditions
- Approval for- =HR case- HR service -= select your HR service name
- source table- HR case table
3. In script add below line of code -
function onLoad() {
var parentTable = g_form.getValue("source_table"); // getting source table as HR Request table so that this will only check when there is approval for HR case
if (g_scratchpad.hrService== "Name of your Hr service" && parentTable == "Hr case table") {// check if the scratchpad variable from display business rule which gives catalog item name as your Hr service and source table is Hr request
// then remove choice value of state which you don't want display for this specific item as below.
g_form.removeOption("state", "cancelled");
g_form.removeOption("state", "not requested");
g_form.removeOption("state", "not_required");
}
}