Hi guys,
Here is my use case: I have three fields: Region, Customer, and Country. In a ticket, the user will pick a region, which will present the corresponding customers. Based on the customer chosen, a specific country will be mapped.
For the most part, this works well.
However, what I can't figure out is, how do I clear values based on whether another field is changed? For example,
I can set customer field to "None" if region is null :
if (region.getValue() == null) {
region.setError("You need to choose a region.")
customer.setFormValue(-1)
}...
But what I really want is the same behavior if either Customer or Region is modified.
For example, let's say I have a Region of "Region1", a customer of "Customer3", and a country of "Mexico". If Customer changes, country should remap to new country. If Region changes (for example to say, Region2), country should be changed to None, and Customer should also be changed to None.
Any tips? *Note* -- When I pick a region, it isn't a one-to-one mapping, which is why I am passing the FieldOptions. Once a specific option from FieldOptions is chosen, that is what maps to Country in a 1-1 relationship.
hi Bryan,
In the else part
else
{
region.clearError();
customer.setFormValue(-
1
)
country.setFormValue(-
1
)
customer.setHidden(false)
country.setHidden(false)
}
else
{
region.clearError();
//
customer.setFormValue(-
1
)
//
country.setFormValue(-
1
)
customer.setHidden(false)
country.setHidden(false)
}
So basically -- looking for help on modifying this so I can get the behavior I want, whether I am creating a ticket, or editing a ticket. Right now, it seems to do what I want only if I create a ticket.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And here is behaviour for Customer:
FormField customer = getFieldByName("Customer") FormField country = getFieldByName("Country") FormField region = getFieldByName("Region") if (region.getValue() == null) { customer.setFormValue(-1) country.setFormValue(-1) } def conMap = [ "Customer1": 14382, // maps to country option of India "Customer2": 14382, // maps to country option of India "Customer3": 14388, // maps to country option of Mexico "Customer4": 14381, // maps to country option of Honduras "Customer5": 14386, // maps to country option of Malaysia "Customer6": 14396, // maps to country option of US "Customer7": 14396, // maps to country option of US "Customer8": 14396, // maps to country option of US "Customer9": 14379, // maps to country option of Guatamala "Customer10": 14372, // maps to country option of Caribbean "Customer11": 14380, // maps to country option of Haiti ] String cusName = customer.getValue() //country.setFormValue(conMap[cusName]) if (cusName == null) { customer.setError("You need to choose a Customer.") country.setFormValue(-1) country.setHidden(true) } else { customer.clearError() country.setHidden(false) country.setFormValue(conMap[cusName]) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
With the following code in the behaviors for the Region and Country fields, I can get the functionality I want.... *except* if I edit the ticket -- then the fields for country and customer go to null, even if I am not editing them.
Here is the behavior I have for Region:
FormField region = getFieldByName("Region") FormField customer = getFieldByName ("Customer") FormField country = getFieldByName("Country") Map fieldOptions = [:] fieldOptions.put ("-1", "None") if (region.getValue() == null) { region.setError("You need to choose a region.") customer.setFormValue(-1) customer.setHidden(true) country.setFormValue(-1) country.setHidden(true) } else { region.clearError(); customer.setFormValue(-1) country.setFormValue(-1) customer.setHidden(false) country.setHidden(false) } switch (region.getValue()) { case "Region1" : fieldOptions.putAll (["14263":"Customer1", "14402":"Customer2", "14266":"Customer3"]) break case "Region2" : fieldOptions.putAll (["14264":"Customer4", "14265":"Customer5", "14270":"Customer6"]) break case "Region3" : fieldOptions.putAll (["14276":"Customer7", "14283":"Customer8", "14286":"Customer9"]) break case "Region4" : fieldOptions.putAll (["14267":"Customer10", "14268":"Customer11"]) break } customer.setFieldOptions (fieldOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.