- 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-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-15-2024 04:47 AM - edited 01-15-2024 04:53 AM
Hi Timi,
Thanks a lot for the detailed reply.
I implemented the solution as follows:
And:
But for some reason, it does not work. I added a debug line in the script include and I do not see it when I submitted that relevant request. It seems that the client script does not call the script include. The alert message that I added to client script is not shown either when I submit the request.
Any idea why?
Thanks!
Best,
Firat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 07:57 PM
The issue might stem from the incorrect creation of the script include initially, lacking the client callable checkbox. You could attempt to delete it and then recreate it.
Regarding your query about the business rule approach – "why don't we write a BR instead of a client script?"
A business rule won't afford you the capability to show or hide an option of a field. However, you can employ a business rule to initiate a scratchpad variable on display. Subsequently, in your client script, you can use that variable to hide options.
Sample.
#Business Rule
(function executeRule(current, previous /*null when async*/) {
var grRITM = new GlideRecord('sc_req_item');
if(grRITM.get(current.getValue('document_id'))){
//you can store the catalog item sys_id in a system property to avoid hard-coding
g_scratchpad.hideApprovalState = (grRITM.getValue('cat_item') === 'e59c31a0930731900c7d72f48aba106b'); //your catalog item sys_id
}
})(current, previous);
#Client Script
function onLoad() {
if (g_form.getValue('source_table') !== 'sc_req_item') {
return;
}
if (g_scratchpad.hideApprovalState === 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');
}
}
Enjoy your result
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:21 AM - edited 01-16-2024 04:22 AM
Hi Timi,
Thanks again for this solution.
I have really no idea why the first solution does not work. I deleted everything and created again, and gave the ACL of the client callable access rule snc_internal. But nothing works. I put that alert there, so once I load the sysapproval_approval form, that alert should pop up but it does not. So the client script is not running, I think for some reason.
function onLoad() {
if (g_form.getValue('source_table') !== 'sc_req_item') {
return;
}
var ga = new GlideAjax('XXX');
alert('hello hello');
There is another client script that I had written, which also modifies that field but it is not active. Do you think even though it is not active it would have an impact?
-- Concerning the second solution.
I create that BR on which table, Approval? And what is the action to trigger that BR? I haven't used any display BR and could not find any information about it?
Thanks!
Best,
Firat