Page 1 of 1

Retrieving the value of a custom field

Posted: Wed Nov 16, 2022 5:20 am
by codvisor
Hi,

I have a custom field in the Order context which is a List of values type.
How can I get the value of this custom field via code snippet?
The code snippet is triggered when a file is saved / closed.

Many thanks !!

Re: Retrieving the value of a custom field

Posted: Fri Nov 18, 2022 1:08 pm
by BobRichards
A drop-down custom field is a list of strings. For this example, let's say you are using this drop-down custom field on the Order context.
DropDownListExample.png
DropDownListExample.png (18 KiB) Viewed 3704 times
First, we then create an automation snippet that runs every time an order is saved. Use the code below for the "Then" clause.

Code: Select all

from System import *
from SoftPro.OrderTracking.Client.Orders import *
# Write to event viewer
import System.Diagnostics as SD

# Context is Order.
def MyFunc():
	s = 'Context: %s' % str(Context)
	s += '\nOrder.DemoDropDown## = ' 
	s += IOrderItem.GetProperty(Context,'DemoDropDown##')
	SD.Trace.TraceWarning(s)

MyFunc()
Finally, we create a new order, set the new field (Order.DemoDropDown##) to "Item #3" then save the order. When the code runs, this message will be written to the Event Viewer.

Code: Select all

Context: Order XAT22002270
Order.DemoDropDown## = Item #3

Re: Retrieving the value of a custom field

Posted: Tue Nov 22, 2022 10:18 am
by codvisor
Perfect!
Many thanks