Create an Attachment Folder

Questions about and code samples for automation process code snippets within Select.
tmeisinger
Posts: 70
Joined: Fri Apr 24, 2015 10:33 am

Create an Attachment Folder

Post by tmeisinger » Fri Mar 01, 2019 11:00 am

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'

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

Re: Create an Attachment Folder

Post by BobRichards » Fri Mar 01, 2019 12:14 pm

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}"
Bob Richards, Software Developer, SoftPro

tmeisinger
Posts: 70
Joined: Fri Apr 24, 2015 10:33 am

Re: Create an Attachment Folder

Post by tmeisinger » Fri Mar 01, 2019 12:39 pm

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).

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

Re: Create an Attachment Folder

Post by BobRichards » Fri Mar 01, 2019 3:19 pm

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!
Bob Richards, Software Developer, SoftPro

Kolinski
Posts: 10
Joined: Sat Oct 20, 2018 12:21 am

Re: Create an Attachment Folder

Post by Kolinski » Thu Mar 14, 2019 8:43 pm

I am trying to use this automation with your "else:" revision but I am getting "Name 'IOrder' is not defined" as my failure reason.

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

Re: Create an Attachment Folder

Post by BobRichards » Fri Mar 15, 2019 10:22 am

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.
Bob Richards, Software Developer, SoftPro

Kolinski
Posts: 10
Joined: Sat Oct 20, 2018 12:21 am

Re: Create an Attachment Folder

Post by Kolinski » Fri Mar 15, 2019 12:25 pm

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!

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

Re: Create an Attachment Folder

Post by BobRichards » Fri Mar 15, 2019 2:21 pm

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...
Bob Richards, Software Developer, SoftPro

Kolinski
Posts: 10
Joined: Sat Oct 20, 2018 12:21 am

Re: Create an Attachment Folder

Post by Kolinski » Fri Mar 15, 2019 3:32 pm

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

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

Re: Create an Attachment Folder

Post by BobRichards » Fri Mar 15, 2019 5:28 pm

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.
Bob Richards, Software Developer, SoftPro

Post Reply