Show only Approved and Rejected in the Approval State

mfhaciahmetoglu
Mega Sage

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.

2 ACCEPTED SOLUTIONS

Tai Vu
Kilo Patron
Kilo Patron

Hi @mfhaciahmetoglu 

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

 

View solution in original post

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:

 

if (g_form.getValue('source_table') === 'sc_req_item') {
        alert('hello hello');
        return;
    }
 
As to why, I am not sure. I understood your logic: if the source table is not sc_req_item, then don't run the code -- which is to say, if it is sc_req_item, then follow the rest of the code. But for some reason, source table is sc_req_item, I don't see that alert and code runs fine. I don't get it but it works.
 
Thanks a lot for the help.

View solution in original post

10 REPLIES 10

Hi @mfhaciahmetoglu 

Yes it's Display business rule and should have a condition Source table is sc_req_item in the Approval record.

Timi_0-1705415146597.png

 

Cheers,

Tai Vu

 

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:

 

if (g_form.getValue('source_table') === 'sc_req_item') {
        alert('hello hello');
        return;
    }
 
As to why, I am not sure. I understood your logic: if the source table is not sc_req_item, then don't run the code -- which is to say, if it is sc_req_item, then follow the rest of the code. But for some reason, source table is sc_req_item, I don't see that alert and code runs fine. I don't get it but it works.
 
Thanks a lot for the help.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @mfhaciahmetoglu 

 

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]

****************************************************************************************************************

Priyanka_786
Tera Guru
Tera Guru

Hi,@mfhaciahmetoglu 

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 -

     g_scratchpad.catItem= current.sysapproval.cat_item.getDisplayValue();
4. Save it
5. Create onLoad Client script on sysapproval_approver table. In this script call scratchpad variable from business rule as below
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");
}
}
 6. Save the client script.
 
I have tested this solution and is working fine for me. 
 
Please mark my response helpful/ accepted if it helps.
Regards,
Priyanka Salunke

Hi Priyanka,

Can you please help me same for HR case for the particular HR service approvals record the state value should be hidden