IronPython set drop down list

Discussions related to writing and managing custom business rules.

Moderator: Phil Barton

Post Reply
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

IronPython set drop down list

Post by danvanf »

Hello,

I am playing with IronPython and have run across a question, which turns out to be 2 to 3 questions. I am attempting to set the drop down list, {{Order.Properties.Address.State}} to "OH" or "Ohio".

The first issue I've had is simply getting to the field. To keep it simple, since {{.Address.City}} is not a drop down I used it to test and filled it in with

Code: Select all

def Address_City_Value(args):
   if (str(args.Context.Owner).StartsWith('Property')):
      args.Value = 'Beavercreek'
   else:
      args.Value = ''
Whereas that is functional, it runs on every {{*.Address.City}} I would prefer to run it only when it's needed I tried things like
def OrderPropertyAddressCity_Value(args):
and
def PropertyAddressCity_Value(args):

Which didn't throw a compile time error, but didn't seem to work either.

Is there a better method to set a {{Order.Property.Address.*}} field than the expensive method I chose?

The main question is how is a drop down list selected? Specifically a {{.State.*}} drop down list.

Thanks for the direction,
Dan
I blog at http://DanVanFleet.com on SoftPro and other things
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: IronPython set drop down list

Post by BobRichards »

OK. Let's answer these questions in no particular order.

There is no way to tell Select to only run a rule on a specific instance of a field within the order (for instance, the "City" field associated with the first Property). Instead, as you demonstrated, you have to do the filtering logic in the rule. This means that a rule can run for many fields that you are not interested in (such as Contact addresses) - but it's very fast. This is why you should always make your custom rules run as quickly as possible.
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: IronPython set drop down list

Post by BobRichards »

You cannot put an order rule on a field that is based on a drop down list. That means States, Product types, etc. You cannot use a rule to set one of these to a specific value. A work-around is if you need to guarantee a specific State value for a property, put a Validation rule on the property City (for instance) and raise an error. When the user clicks on the error message, the hot spot will take you to the City, but that is physically pretty close on the correct screen. Just make sure the error message is clear that the problem is with the State value.
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: IronPython set drop down list

Post by BobRichards »

Order rules will always be overwritten by user input. In your code, you potentially set the value to 'BeaverCreek'. However, if the user manually types in a different value, your value will be discarded and the order rule WILL STOP RUNNING FOR THAT SPECIFIC FIELD. The only way to restart the rule is for the user to hit F2 while in the field box. After that, your rule will run and the value will be restored to 'BeaverCreek'.

Things to note:
  1. If the user types in a Property's Address City field, the order rule will stop updating that field. However, the rule will run for all other instances of the Address City in the order (such as the Contacts) that do not have user entered data.
  2. Rules run with the permissions of the users. If the user cannot do it, the rule cannot do it.
  3. If a field is Read Only, the user CANNOT write to the field, but the rule CAN. Use this to prevent the user from altering the value written by your rules if you cannot allow user modification. Create a ReadOrder rule for each Value rule as needed.
Bob Richards, Senior Software Developer, SoftPro
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Re: IronPython set drop down list

Post by danvanf »

Thanks Bob. That all makes sense. Quick comments in order

Quite cool on the execution speed, the Profiling Session Report showing 75 thousand calls in .39 seconds is impressive. I was being overly concerned about a couple hundred.

Go figure I'd select something impossible like setting a drop down list. They only do business in Ohio, I liked a business rule rather than a template setting for the Property.Address default. Validation wouldn't help this process but thanks for pointing it out since it will work in many cases.

A great synopsis of how rules run and part of why they are cool. For me, the other part is they exist for all instances of an object or context, and as I'm learning that's both a blessing and a curse. Isn't it all. <smile>

I'm rolling up the learning curve, thanks for the help,
Dan
I blog at http://DanVanFleet.com on SoftPro and other things
Melissa McBerkowitz
Posts: 91
Joined: Wed Sep 10, 2008 3:33 pm
Location: Raleigh, NC
Contact:

Re: IronPython set drop down list

Post by Melissa McBerkowitz »

Update on this thread: Select v4.0 SP4 (aka 4.0.4 aka 4.0.30302.62) added the ability to set drop-downs such as property state through Python rules.
Melissa McBerkowitz
VP of Product Strategy, SoftPro
Post Reply