Set Variables Mandatory Depending on Task State and Checkbox State

Tamara11
Mega Sage

Hi Team,

I have a catalog item with variables and behaviors that only show/apply on the task form.

 

On the task form, depending on whether a checkbox (laptop) is not true:

    Display Reference field computer_on_loan as mandatory

    Display Checkbox computer_not_found (unchecked)

Tamara11_0-1694370534916.png

Checking computer_not_found

    Hide Reference field computer_on_loan

    Show Single line text field name_of_computer as mandatory.

Tamara11_1-1694370742002.png

 

The purpose for this is so that technicians can document the device that is loaned out.

 

The problem is that when a task is first created and in the Open state, a representative has to assign it to a tech.

The representative cannot assign it to the tech without entering the mandatory fields, but they don't know which device will be deployed.

 

We need to set computer_on_loan mandatory ONLY when the task state is Work in Progress (2?) AND computer_not_found != true.

 

I've tried myriad permutations of adding scripting to my Catalog UI Policy via the run scripts checkbox and separate Catalog Client scripts and seem to get close, but the closest I've come results in the computer_not_found check box change being ignored.  The furthest I've come is other, unrelated variable states changing and at one point, the right click >> save (etc) capability on the task form was even broken!

 

I've reordered and disabled all of the UI policies and worked my way through re-enabling them. 

I've tried OnLoad and OnChange variations with the Catalog Client Scripts and Reverse if False/Don't reverse if false on Catalog UI Policies.
It seems as if unchecking run scripts on a Catalog UI policy doesn't really matter if the code is left in, because the change didn't take effect until I removed the code.

 

Here's an example of the code I'm trying to use.

 

	if(g_form.getValue('state') == 2){
		if(g_form.getValue('computer_not_found') != true){
			g_form.setMandatory('name_of_computer_on_loan',true);
		}
	} else {
		g_form.setMandatory('name_of_computer_on_loan',false);
	}

 

 

For the if false portion:

 

	if(g_form.getValue('state') != 2){
		if(g_form.getValue('computer_not_found') == true){
			g_form.setMandatory('name_of_computer_on_loan',false);
		}
	}

 

 

I've been trying different variations for days so it's not really feasible to share every result.  They've been pretty wild though.

1 ACCEPTED SOLUTION

Tamara11
Mega Sage

I think I've got it!

I created a new Catalog UI Policy and made its Order before the Show Computer Reference and Show Computer Text Catalog UI Policies.

 

In the Catalog UI Policy:

  • Applies only on tasks

Conditions

  • laptop is true
  • computer_not_found is not true

 

  • On Load checked
  • Reverse if False checked

On the Script tab:

  • Run scripts checked
  • Execute if true:

 

 

function onCondition() {
if(g_form.getValue('state') == 2){
	g_form.setMandatory('name_of_computer_on_loan', true);

}​

 

 

  • Execute if false:

 

 

function onCondition() {
	g_form.setMandatory('name_of_computer_on_loan', false);

}​

 

 

Thanks for thinking this through with me!  Now I'm going to go think about something else and test it again later.

GAH! Now I have to do the same thing for the hot spot variable!🤦‍♀️

View solution in original post

5 REPLIES 5

Are Kaveri
Tera Contributor

Your question don’t have clear to answer. But if you want to make mandatory for the variables based on task state. Please write catalog UI policy and check the checkbox to catalog and target record. 

Thanks.  I didn't intend to post a question with no post body.  A normal UI Policy isn't working because I need to use the task state. 

I intended to post more detail, but between my slow loading computer and this site, somehow it skipped right past the post body after offering me a bunch of similar threads.

 

Then I tried to delete it, but got sidetracked while waiting for the page to load and you responded.  I'll try to delete and repost.

Edit: It won't let me delete, I guess once someone replies.  So, I'll update the body with the details.  Should take about 30 minutes.

Sandeep Rajput
Tera Patron
Tera Patron

@Tamara11 Please create a "UI Policy" and add conditions to check task state and checkbox state in it. In UI Policy actions make your fields mandatory.

Thank you, Sandeep. Please see the updated post for details.  I must be missing something as I don't see any way to get the task state without using scripting and my results in that arena have been unexpected.

 

I'm probably overthinking it.