Make visible variable in RITM only if Approval is granted

Lkowalski
Tera Contributor

Hello,

 

Could yo help on below issue ?

 I have to make visible variable in RITM only if below requirements will be passed:

 For example, for variable1

 

 If [Variable2]= No AND [Variable3]= No

 OR

 If [Variable2]= Yes OR [Variable3]= Yes, AND required approval is granted from Single Approval

 OR

 If [Variable2]= Yes AND [Variable3]= Yes, AND both required approvals are granted (from Single Approval and Group Approval)

 

I made a below catalog client script which Applies on Requested Items, but it did not work.

function onLoad() {
   //Type appropriate comment here, and begin script below
      if (variables.variable2== 'No' && variables.variable3== 'No') {
        if (variables.variable2== 'Yes' || variables.variable3== 'Yes' && g_scratchpad.isApproved == 'true') {
            if (variables.variable2== 'Yes' && variables.variable3== 'Yes' && g_scratchpad.isApproved == 'true') {
                g_form.setDisplay(‘variables.variable1’,true);
                g_form.setMandatory(‘variables.variable1’,true);
            }
        }
    }
}

 

Thank you for any help.

Regards,

Lukas

1 ACCEPTED SOLUTION

Hi,

so the display BR is on RITM table then this line is wrong;

update this

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

    // Add your code here
    var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery("sysapproval", current.sys_id);
    gr.addQuery("state", "approved");
    gr.query();
    if (gr.next()) {
        g_scratchpad.isApproved = 'true';
    }
    g_scratchpad.isApproved = 'false';

})(current, previous);

Regards
Ankur

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

View solution in original post

10 REPLIES 10

ankitshaw625
Tera Expert

You're currently applying an AND operation among these set of conditions by nesting the if blocks. You need to check all these at the same level. You can try this:

function onLoad() {
  var conditionA = variables.variable2== 'No' && variables.variable3== 'No';

  var conditionB = variables.variable2== 'Yes' || variables.variable3== 'Yes' && g_scratchpad.isApproved == 'true';

  var conditionC = variables.variable2== 'Yes' && variables.variable3== 'Yes' && g_scratchpad.isApproved == 'true';



  if (conditionA || conditionB || conditionC) {

    g_form.setDisplay(‘variables.variable1’,true);

    g_form.setMandatory(‘variables.variable1’,true);

  }
}

 

Hi Ankit,

 

Thank you for suggestion.

Unfortunately my variable1 is still not mandatory and appear after RITM was created with variable 2 and variable 3 before it was changed. Changing variable 2 and 3 make not impact in variable 1.

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I think you are using display business rule on RITM table

share script for that

Also you should use normal client script and not catalog client script

ensure you are comparing correct choice value of No and Yes

Update script as this

function onLoad() {
	//Type appropriate comment here, and begin script below
	if (g_form.getValue('variables.variable2') == 'No' && g_form.getValue('variables.variable3') == 'No') {
		if (g_form.getValue('variables.variable2') == 'Yes' || g_form.getValue('variables.variable3') == 'Yes' && g_scratchpad.isApproved == 'true') {
			if (g_form.getValue('variables.variable2') == 'Yes' && g_form.getValue('variables.variable3') == 'Yes' && g_scratchpad.isApproved == 'true') {
				g_form.setDisplay('variables.variable1',true);
				g_form.setMandatory('variables.variable1',true);
			}
		}
	}
}

Regards
Ankur

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

Hi Ankur,

 

Yes I have a Display business rule on RITM table:

 

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

	// Add your code here
	var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", current.request_item);
	gr.addQuery("state", "approved");
	gr.query();
	if (gr.next()) {
		g_scratchpad.isApproved = 'true';
	}
	g_scratchpad.isApproved = 'false';

})(current, previous);