Page 1 of 2
Create an Attachment Folder
Posted: Fri Mar 01, 2019 11:00 am
by tmeisinger
In Automation, if I don't have an Attachment Folder, I would like to create it. I'm doing this when a Document is Added. I'm struggling with how to Create Folder, any help would be appreciated. I'm getting
"unexpected token '<newline>'" as the reason my process fails.
Code: Select all
# Context ( IAttachmentItem) is the document that was attached to order!
# Get top level attachment folder at "\{OrderNumber}\Attachments"
topFolder = IOrder.Attachments.GetValue(Context.Parent.Order)
findFolder = [a for a in topFolder.Items if a.Name == 'FolderName']
if findFolder:
# Found the target folder
destFolder = findFolder[0]
else
# Create Folder at "\{OrderNumber}\Attachments\{folder}"
newFolder = topFolder.NewFolder()
newFolder.Name = 'FolderName'
Re: Create an Attachment Folder
Posted: Fri Mar 01, 2019 12:14 pm
by BobRichards
You are missing the colon after the else statement around line 10. Correction is below.
Code: Select all
destFolder = findFolder[0]
else:
# Create Folder at "\{OrderNumber}\Attachments\{folder}"
Re: Create an Attachment Folder
Posted: Fri Mar 01, 2019 12:39 pm
by tmeisinger
Thank you, still learning Python and the colon was missing in the handout I got at the user group a couple of years ago (Custom Order Rules for SoftPro Select).
Re: Create an Attachment Folder
Posted: Fri Mar 01, 2019 3:19 pm
by BobRichards
No problem. Automation code is the hardest code to write since it does not have the developer tools that Custom Order Rules have. Good luck!
Re: Create an Attachment Folder
Posted: Thu Mar 14, 2019 8:43 pm
by Kolinski
I am trying to use this automation with your "else:" revision but I am getting "Name 'IOrder' is not defined" as my failure reason.
Re: Create an Attachment Folder
Posted: Fri Mar 15, 2019 10:22 am
by BobRichards
Please submit your code and make sure the automation context is IAttachmentItem. Please put your code inside code tags ("</>" button) so it will be properly spaced and readable.
Re: Create an Attachment Folder
Posted: Fri Mar 15, 2019 12:25 pm
by Kolinski
I'm not sure how to set the automation context. I know just enough to cause trouble but not enough to always know what I'm doing. I've tried to search the forum and piece together other code or use ones that I currently have running but no luck.
Here's what I was using to get the error in my last post:
Code: Select all
# Context ( IAttachmentItem) is the document that was attached to order!
# Get top level attachment folder at "\{OrderNumber}\Attachments"
topFolder = IOrder.Attachments.GetValue(Context.Parent.Order)
findFolder = [a for a in topFolder.Items if a.Name == 'FolderName']
if findFolder:
# Found the target folder
destFolder = findFolder[0]
else:
# Create Folder at "\{OrderNumber}\Attachments\{folder}"
newFolder = topFolder.NewFolder()
newFolder.Name = 'FolderName'
As always your help is appreciated and if there is any place you can direct me to learn more I'd appreciate that as well!
Re: Create an Attachment Folder
Posted: Fri Mar 15, 2019 2:21 pm
by BobRichards
The original poster left out the imports at the top of the file that tells Python where to find items - including the one for IOrder. Add them back:
Code: Select all
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
# Add the rest of the Python code below...
Re: Create an Attachment Folder
Posted: Fri Mar 15, 2019 3:32 pm
by Kolinski
Now I get
'Order' object has no attribute 'Parent' with this code
Code: Select all
from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
# Context ( IAttachmentItem) is the document that was attached to order!
# Get top level attachment folder at "\{OrderNumber}\Attachments"
topFolder = IOrder.Attachments.GetValue(Context.Parent.Order)
findFolder = [a for a in topFolder.Items if a.Name == 'FolderName']
if findFolder:
# Found the target folder
destFolder = findFolder[0]
else:
# Create Folder at "\{OrderNumber}\Attachments\{folder}"
newFolder = topFolder.NewFolder()
newFolder.Name = 'FolderName'
I've attempted to steal some coding from the previous post regarding adding attachments to folders but have had no luck. Thank you
Re: Create an Attachment Folder
Posted: Fri Mar 15, 2019 5:28 pm
by BobRichards
Send me the automation process rule that that you have created so I can help. Automation is not easy.
- Select the SPAdmin tab.
- Go to the Automation / Processes page.
- Double-click your process (or right-click it and select Properties).
- Manually copy the "Rule:" section to a post.
If you have more than one code snippet in your rule, make sure you indicate which one is running the code from your post.