Settlement Date format 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

Settlement Date format in a code snippet

Post by cklahr »

Hi,

I'm trying to get the settlement date to appear in an email rendered via automation, but I'm getting an error. Any idea what the correct format would be?

Also, how can I get the format of the text to match the rest of the text?

Thank you!

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>Settlement Date has been added/updated in the file to </hl><pre>' + Context.SettlementDate + ' .',
#		+ JavaScriptSerializer().Serialize(Context.FileHeld.HeldByUser)
		'subject': 'Settlement Date update 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)

for contact in Context.Contacts:
	if hasattr(contact, 'OtherType') and contact.OtherType == 'Funder':
		if contact.Email:
			SendEmail('selectnotifications@madisoncres.com', contact.Email)	
if Context.FileHeld.HeldByUser.EmailAddress:
	SendEmail('selectnotifications@madisoncres.com', Context.FileHeld.HeldByUser.EmailAddress)	
cklahr
Posts: 71
Joined: Tue Oct 27, 2009 3:32 am

Re: Settlement Date format in a code snippet

Post by cklahr »

The issue appears to be with the "Context.SettlementDate" field. When I remove that or try another field, it works.

Thank you very much!
PaulMcCullough
Posts: 23
Joined: Wed Jul 12, 2023 11:29 am

Re: Settlement Date format in a code snippet

Post by PaulMcCullough »

To format SettlementDate you need to call ToString(). If you don't pass any parameters it will print the date and time including the seconds. You can also pass any .NET DateTime standard or custom format string into the ToString() call to change the format.

Here are some examples:

Code: Select all

	# output looks like 1/31/2024 10:15:00 AM
	Context.SettlementDate.ToString()
	
	# output looks like 1/31/2024 10:15 AM
	Context.SettlementDate.ToString('g')
	
	# only the date is output 1/31/2024
	Context.SettlementDate.ToString('d')
For more formatting options you can visit the Microsoft web site to see Standard date and time format strings or if you need a more customized format, Custom date and time format strings
cklahr
Posts: 71
Joined: Tue Oct 27, 2009 3:32 am

Re: Settlement Date format in a code snippet

Post by cklahr »

That worked. Thank you so much!!
Post Reply