Visibility based on

Questions about and code samples for adding visibility conditions within Select
Post Reply
Kolinski
Posts: 12
Joined: Sat Oct 20, 2018 12:21 am

Visibility based on

Post by Kolinski »

I'm looking to set a documents visibility based on a payee code in a CDF or HUD line and whether that line has a $ value in it or not. Is this possible?

The specific fields I'm referencing are: "Order.CDFs.DueFromSellerSection.Lines[12].Charges.Contact" and "Order.CDFs.DueFromSellerSection.Lines[12].Charges.Amount"

If the payee code = "E" and the value is greater than $0 or not blank then I want the document to show.

Thank you
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Visibility based on

Post by BobRichards »

Here is an example of creating your visibility rule. The CDF code is provided but not the HUD - you should be able to use what I provided as a guide. If you want to allow the document to be visible always for CSS, then remove the "pass" instruction and replace it with "enableReport = True".

At the top of the file, I defined the integer values for the Order.SettlementType enumeration. In a Custom Order Rules (and others), we would simply include the namespace "SoftPro.Accounting.Client.Orders" in the file where the enumeration is defined already, but you are not allowed to add namespaces to Visibility Rule files.

We also had to handle the Contact.Code property carefully. If the user has not filled in the Contact field, "line.Contact" is None. In this case, attempting to get the value of "line.Contact.Code" will throw an exception. The construct I used is common in Python and almost reads like normal English.

Code: Select all

# From enumeration in SoftPro.Accounting.Client.Orders
SettlementType_CDF = 0
SettlementType_CSS = 2
SettlementType_HUD1 = 1

# Later logic will set variable to True if report should be run.
enableReport = False

if int(Order.SettlementType) == SettlementType_CSS:
	pass
	
elif int(Order.SettlementType) == SettlementType_CDF:
	# Search all lines in first CDF for line N.12
	allLines = Order.CDFs[0].Lines
	matches = [l for l in allLines if l.SectionNumber == 'N.12']
	if len(matches) == 1:
		# We found N.12 - now run final tests.
		line = matches[0]
		code = '' if line.Contact is None else line.Contact.Code
		amount = line.Amount
		enableReport = code == 'E' and amount > 0
			
elif int(Order.SettlementType) == SettlementType_HUD1:
	pass
	
# Return enable flag after scanning the order.
return enableReport
Bob Richards, Senior Software Developer, SoftPro
Kolinski
Posts: 12
Joined: Sat Oct 20, 2018 12:21 am

Re: Visibility based on

Post by Kolinski »

Thanks for the response! That works perfectly but I think you've given me too much credit. I've attempted to make the necessary changes to use this in a HUD file but can't get it to work.

"SectionNumber" appears to be incorrect and brings up the first error so I cant get any further to know if there will be others after that. What did I do incorrectly? Am I anywhere close? Thanks for the help!

# From enumeration in SoftPro.Accounting.Client.Orders
SettlementType_CDF = 0
SettlementType_CSS = 2
SettlementType_HUD1 = 1

# Later logic will set variable to True if report should be run.
enableReport = False

if int(Order.SettlementType) == SettlementType_CSS:
pass

elif int(Order.SettlementType) == SettlementType_HUD1:
# Search Section 500 in first HUD1 for line 517
allLines = Order.HUDs[0].Section500
matches = [l for l in allLines if l.SectionNumber == '517']
if len(matches) == 1:
# We found 517 - now run final tests.
line = matches[0]
code = '' if line.HUDTo is None else line.HUDTo.Code
amount = line.Amount
enableReport = code == 'E' and amount > 0

elif int(Order.SettlementType) == SettlementType_CDF:
pass

# Return enable flag after scanning the order.
return enableReport
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Visibility based on

Post by BobRichards »

Please repost your source code by putting it between code tags so I can read it easier.
  • Click the "Code display" button. It is fifth from the left just above where you type in posts (label: </>)
  • Put your source code (only) between the open and close "code" tags.
  • Click Preview at the bottom to make sure it looks OK.
Thanks
Bob Richards, Senior Software Developer, SoftPro
Kolinski
Posts: 12
Joined: Sat Oct 20, 2018 12:21 am

Re: Visibility based on

Post by Kolinski »

Code is below and thanks for your help! I basically copied your CDF code and modified it as I thought I should but it definitely isn't correct.

Code: Select all

# From enumeration in SoftPro.Accounting.Client.Orders
SettlementType_CDF = 0
SettlementType_CSS = 2
SettlementType_HUD1 = 1

# Later logic will set variable to True if report should be run.
enableReport = False

if int(Order.SettlementType) == SettlementType_CSS:
pass

elif int(Order.SettlementType) == SettlementType_HUD1:
# Search Section 500 in first HUD1 for line 517
allLines = Order.HUDs[0].Section500
matches = [l for l in allLines if l.SectionNumber == '517']
if len(matches) == 1:
# We found 517 - now run final tests.
line = matches[0]
code = '' if line.HUDTo is None else line.HUDTo.Code
amount = line.Amount
enableReport = code == 'E' and amount > 0

elif int(Order.SettlementType) == SettlementType_CDF:
pass

# Return enable flag after scanning the order.
return enableReport
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Visibility based on

Post by BobRichards »

You can use the Lines collection on the HUD just like on the CDF to find line 512.

Code: Select all

...
elif int(Order.SettlementType) == SettlementType_HUD1:
    allLines = Order.HUDs[0].Lines
    matches = [l for l in allLines if l.Number == 512]
    if len(matches) == 1:
        line = matches[0]
        ...
Bob Richards, Senior Software Developer, SoftPro
Kolinski
Posts: 12
Joined: Sat Oct 20, 2018 12:21 am

Re: Visibility based on

Post by Kolinski »

Got it to work. Thank you!
Post Reply