- 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
01-16-2024 06:27 AM
Yes it's Display business rule and should have a condition Source table is sc_req_item in the Approval record.
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
01-15-2024 02:08 AM
May I know the business need of same and that is only for specific catalog.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 05:31 AM
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- requested item- item -= select your catalog item name
- source table- sc_req_item
3. In script add below line of code -
function onLoad() {
var parentTable = g_form.getValue("source_table"); // getting source table as request table so that this will only check when there is approval for request
if (g_scratchpad.catItem == "Name of your catalog item" && parentTable == "sc_req_item") {// check if the scratchpad variable from display business rule which gives catalog item name as your catalog item and source table is request item
// 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");
}
}
|
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 12:00 PM
Hi Priyanka,
Can you please help me same for HR case for the particular HR service approvals record the state value should be hidden