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 @Sakthivel M S 

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 -

     g_scratchpad.hrService= current.sysapproval.(hr-service field-name).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 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");
}
}
 Hope this helps.
Please mark my response helpful/ accepted if it helps.
Regards,
Priyanka Salunke