We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Hide Choices in Approval table state

armanoj
Mega Sage

Hi ,

 

I'm trying to hide the choice value in state field in the approval tabe base on the source table. I used onload client scrit to hide the option but working .

1 ACCEPTED SOLUTION

@armanoj 

Another approach is to use a Display Business Rule to pass the source table value to the client using g_scratchpad, and then reference that value in your Client Script.

(function executeRule(current, previous) {
g_scratchpad.sourceTable = current.getValue('source_table');
})(current, previous);

Client Scripit

var sourceTable = g_scratchpad.sourceTable;

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@armanoj 

it should work fine

share your onLoad script and what debugging did you do?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@RajveerSingh @Ankur Bawiskar 

Application : Global
 
function onLoad() {

    // Check if approval is for Activity Master
    var sourceTable = g_form.getValue('source_table');

    if (sourceTable == 'sn_vdr_risk_asmt_activity_masters') {

        // Hide specific choices
        g_form.removeOption('state', 'cancelled');
        g_form.removeOption('state', 'not_requested');
        g_form.removeOption('state', 'not_entitled');
        g_form.removeOption('state', 'action_complete');
        g_form.removeOption('state', 'action_work_in_progress');
        g_form.removeOption('state', 'send_back');
        g_form.removeOption('state', 'approve_with_caveats');
        g_form.removeOption('state', 'request_revision');
       

    }
}

@armanoj 

Another approach is to use a Display Business Rule to pass the source table value to the client using g_scratchpad, and then reference that value in your Client Script.

(function executeRule(current, previous) {
g_scratchpad.sourceTable = current.getValue('source_table');
})(current, previous);

Client Scripit

var sourceTable = g_scratchpad.sourceTable;

@armanoj 

you won't get the source table using this line

var sourceTable = g_form.getValue('source_table');

So use this approach

1) Display BR on sysapproval_approver table

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.tableName = current.source_table.toString();

})(current, previous);

2) update your onLoad script with this

function onLoad() {

    // Check if approval is for Activity Master
    var sourceTable = g_scratchpad.tableName;
    if (sourceTable == 'sn_vdr_risk_asmt_activity_masters') {
        // Hide specific choices
        g_form.removeOption('state', 'cancelled');
        g_form.removeOption('state', 'not_requested');
        g_form.removeOption('state', 'not_entitled');
        g_form.removeOption('state', 'action_complete');
        g_form.removeOption('state', 'action_work_in_progress');
        g_form.removeOption('state', 'send_back');
        g_form.removeOption('state', 'approve_with_caveats');
        g_form.removeOption('state', 'request_revision');
    }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader