Page 1 of 1

Populate Custom Field with Automation Code Snippet

Posted: Mon Jul 08, 2019 2:47 pm
by smstreet83
I need to get a custom field to populate with the name of the user who published a commitment to the file. I was able to get a COR to work on a test file, but when I changed the coding around for the new context, it doesn't work. My automation process says it has completed successfully, but the field I'm trying to populate isn't filled in when I go back into the order. Am I close or should I go back to the drawing board and start from scratch again? Thanks in advance.

When a document is attached
and document name contains 'Commitment'
then do the following:
run code snippet

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *

order = Context.Parent.Order
aFolder = IOrder.Attachments.GetValue(Context.Parent.Order)
publishedBy = IOrderItem.GetProperty(order, 'Publisher##')
	
for n in aFolder.Items:
	if n.Name == 'Commitment':
		publishedBy = n.LastModifiedBy

Re: Populate Custom Field with Automation Code Snippet

Posted: Thu Jul 11, 2019 10:30 am
by BobRichards
Please furnish the COR so I can compare their logic. Thanks.

Re: Populate Custom Field with Automation Code Snippet

Posted: Thu Jul 11, 2019 12:03 pm
by smstreet83
When I use the following code as a COR, my custom field populates correctly. When I post it as the code snippet in my Automation Process, it says "completed successfully", but it doesn't populate my custom field. I assume it's a Context issue, I'm just not very familiar with the Attachments Context.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *

def Publisher_Value(args):	
	order = args.Context.Root
	publisher = IOrderItem.GetProperty(order, 'Publisher##')
	docs = IOrder.Attachments.GetValue(args.Context.Root)
	
	for n in docs.Items:
		if n.Name == 'Commitment':
			modUser = n.LastModifiedBy
			args.Value = modUser
		
Publisher_Value.__name__ = 'Order_Publisher##_Value'

Re: Populate Custom Field with Automation Code Snippet

Posted: Thu Jul 11, 2019 3:09 pm
by BobRichards
The problem is related to the fact that copying a property's value to string does not make that string instance an alias for the property. To set the value of a property (outside of a COR), you need to use SetProperty(). CORs effectively do Get/SetProperty() operations for you.

Code: Select all

...
for n in aFolder.Items:
    if n.Name == 'Commitment':
        IOrderItem.SetProperty(order, 'Publisher##, n.LastModifiedBy)