Questions about and code samples for automation process code snippets within Select.
-
smstreet83
- Posts: 2
- Joined: Thu May 04, 2017 1:15 pm
Post
by smstreet83 » Mon Jul 08, 2019 2:47 pm
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
-
BobRichards
- Posts: 1006
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
-
Contact:
Post
by BobRichards » Thu Jul 11, 2019 10:30 am
Please furnish the COR so I can compare their logic. Thanks.
Bob Richards, Software Developer, SoftPro
-
smstreet83
- Posts: 2
- Joined: Thu May 04, 2017 1:15 pm
Post
by smstreet83 » Thu Jul 11, 2019 12:03 pm
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'
-
BobRichards
- Posts: 1006
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
-
Contact:
Post
by BobRichards » Thu Jul 11, 2019 3:09 pm
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)
Bob Richards, Software Developer, SoftPro