Page 1 of 1

How to identify Checklist tasks in a code snippet

Posted: Tue Oct 31, 2023 7:11 am
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)

Re: How to identify Checklist tasks in a code snippet

Posted: Tue Oct 31, 2023 10:45 am
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 7057 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"?

Re: How to identify Checklist tasks in a code snippet

Posted: Mon Nov 06, 2023 7:18 am
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)

Re: How to identify Checklist tasks in a code snippet

Posted: Mon Nov 06, 2023 11:21 am
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!