How to identify Checklist tasks in a code snippet

Questions about and code samples for automation process code snippets within Select.
Post Reply
cklahr
Posts: 71
Joined: Tue Oct 27, 2009 3:32 am

How to identify Checklist tasks in a code snippet

Post by cklahr »

Hi,

I'm trying to run the below code in an automation process, and I'm getting an error "'Checklist task' object has no attribute 'Task'". Are you able to assist with revising this accordingly?

Thank you so much!!

from System import *
import clr
clr.AddReference('System.Net.Http')
from System.Net.Http import HttpClient, StringContent
from System.Text import Encoding
clr.AddReference('System.Web.Extensions')
from System.Web.Script.Serialization import JavaScriptSerializer
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

def SendEmail(fromAddress, toAddress):
email = {
'to': toAddress,
'from': fromAddress,
'body': '<hl>Please remember to record a Notice of Settlement for this order.</hl><pre>',
# + JavaScriptSerializer().Serialize(Context.FileHeld.HeldByUser)
'subject': 'NOS required for ' + Context.EmailSubjectLine
}
js = JavaScriptSerializer()
params = js.Serialize(email)
content = StringContent(params, Encoding.UTF8, 'application/json')
client = HttpClient()
response = client.PostAsync('http://sharedapi.madisoncres.com/functions/email', content).Result
print(response)

tasks = Context.ChecklistTasks
if tasks:
for task in tasks:
if task.Task == "05. Printed and Saved to Web" and task.CompletedBy and task.CompletedBy.EmailAddress:
SendEmail('selectnotifications@madisoncres.com', task.CompletedBy.EmailAddress)
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to identify Checklist tasks in a code snippet

Post by BobRichards »

Please repost and put Python code in a "code" block to preserve the whitespace if you have any further issue. You can use the
2023-10-31_10-37-30.jpg
2023-10-31_10-37-30.jpg (1.06 KiB) Viewed 6239 times
button to do this.

The ChecklistTask object does not have a "Task" property. Use the field code browser to verify the properties an object has. Perhaps you mean "task.Description"?
Bob Richards, Senior Software Developer, SoftPro
cklahr
Posts: 71
Joined: Tue Oct 27, 2009 3:32 am

Re: How to identify Checklist tasks in a code snippet

Post by cklahr »

Okay, thank you! I got it to work with the below code snippet.

Code: Select all

from System import *
import clr
clr.AddReference('System.Net.Http')
from System.Net.Http import HttpClient, StringContent
from System.Text import Encoding
clr.AddReference('System.Web.Extensions')
from System.Web.Script.Serialization import JavaScriptSerializer
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

def SendEmail(fromAddress, toAddress):
	email = {
		'to': toAddress,
		'from': fromAddress,
		'body': '<hl>Please remember to record a Notice of Settlement for this order.</hl><pre>',
#		+ JavaScriptSerializer().Serialize(Context.FileHeld.HeldByUser)
		'subject': 'NOS required for ' + Context.EmailSubjectLine
	}
	js = JavaScriptSerializer()
	params = js.Serialize(email)
	content = StringContent(params, Encoding.UTF8, 'application/json')	
	client = HttpClient()
	response = client.PostAsync('{url}/functions/email', content).Result
	print(response)

tasks = Context.ChecklistTasks
if tasks:
    for task in tasks:
        if task.Description == '05. Printed and Saved to Web' and task.CompletedBy and task.CompletedByUser.EmailAddress:
            SendEmail('{email address}', task.CompletedByUser.EmailAddress)
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to identify Checklist tasks in a code snippet

Post by BobRichards »

Congratulations on getting it working! Hope you don't mind but I edited your post to remove any URLs and email addresses to avoid the possibility of your services being spammed.

Thanks for posting the final product so others can use your example!
Bob Richards, Senior Software Developer, SoftPro
Post Reply