back to top

Defaulting the TO address in the Creatio Freedom UI Email Message Composer

The Freedom UI Message Composer component is used for things like posting a message to a feed or sending an email message. When you’re using it for sending an email message, the EmailComposer sub component is used. This article will cover how to default the “TO” of the email.

Scenario

In this scenario, I will be adding the Message Composer to the contact edit page. I’ve added it to the Timeline tab, so it works in a similar way to how it does on the Case edit page. The end result will be that you can send the contact an email from the Timeline tab in the same way as sending an email from a case. The To of the email will default to the email address of the contact.

Retrieving the Contact Email Address

The first thing we’ll need to do is to be able to get the contact’s email address. The email address itself doesn’t exist on the contact page. What you’re seeing on the contact page is the Communication Options component, which displays the email and phone numbers. So, this means that we can’t just retrieve the email from an attribute since it’s not part of the page’s data source. However, we’ll add the Email and Name to the page’s datasource by merging them in the viewModelConfigDiff. See an article on that topic here. Our code to add those will look as follows:

viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
	{
		"operation": "merge",
		"path": [
			"attributes"
		],
		"values": {
			"ContactEmail": {
				"modelConfig": {
					"path": "PDS.Email"
				}
			},
			"ContactName": {
				"modelConfig": {
					"path": "PDS.Name"
				}
			}
		}
	}
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,

With those added to the page’s data source, we’ll be able to retrieve them normally using those attributes.

Setting the Email Message Composer’s TO Attribute

The Email Message Composer’s TO field is bound to an attribute that will be the same as the EmailComposer’s name (The EmailComposer, not the MessageComposer), followed by “_To”. If my EmailComposer component is named “EmailComposer_tznu5e0” the attribute for the To will be “EmailComposer_tznu5e0_To”. One thing to note, this attribute is expecting an array of strings, not jus a single string. We’ll get the email value when the page loads and model is ready, then set the To attribute using the following code:

{
	request: "crt.HandleViewModelInitRequest",
	handler: async (request, next) => {
		await next?.handle(request);
                  
		request.$context.events$.subscribe((async (evt) => {
			const modelMode = await request.$context.getPrimaryModelMode();

			if (modelMode === "update" && evt?.type === "finish-load-model-attributes" && evt?.payload?.ContactEmail && evt?.payload?.ContactName) {
				// get email and name values from loaded data
				const email = await request.$context.ContactEmail;
				const name = await request.$context.ContactName;
				const toAddress = (email ? name + " <" + email + ">" :"");
				
				// set as "To" - make sure to enclose email in an array
				request.$context.EmailComposer_tznu5e0_To = [ toAddress ];
			}
        
		}));
	}
}

The end result will look as follows:

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Ryan Farley
Ryan Farleyhttps://customerfx.com/article/author/ryanfarley/
Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

5 COMMENTS

  1. Hello Ryan, thank you for your article!
    I was wondering if it’s possible to do the same logic, but in the opportunities form page, to default the TO address based on the Contact and the Account in the page. Thank you!

    • Hi Oleksandr,

      Yes. The method outlined in this article would work for an opportunity as well. The only real difference would be the “path” of the attributes. For the opportunity contact, the path would look like: “PDS.Contact.Name” and “PDS.Contact.Email”. All else would remain the same.

      Ryan

  2. Similar to how we set a default value for the ‘To’ attribute, I have a case to apply a filter on the same attribute. However, since the message composer belongs to a different component, I’m unable to access the attribute name or attach a load data request to it.

    Could you please suggest any possible approaches or alternatives to achieve this?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

AI Readiness Checklist for CRM Teams: Is Your CRM System Ready for AI?

Before using AI in Creatio, make sure your CRM data, users, processes, and automation foundation are ready. Use this practical AI readiness checklist for CRM teams.

Build Your Creatio AI Skills with the 2026 AI Summer Program

Join Creatio’s free 2026 AI Summer Program to learn how to identify, build, deploy, and manage AI agents.

Creatio 10x Is Coming: Join the Webinar to Explore the Future of AI-Native CRM

Learn what's new in Creatio 10x and how AI-native CRM, agentic AI, and no-code automation are shaping the future of customer relationship management. Join the upcoming webinar and discover what's next.

Creatio Unlimited Pricing Explained: AI Packages, Costs, Pros & Cons

Learn what Creatio’s new Unlimited pricing model includes, what it doesn’t include, how AI Action packages work, and the pros and cons for businesses evaluating Creatio.

Using the AI Prompt to Create Dynamic Folders in Creatio

Using Creatio's AI prompt to create the filter for a dynamic folder works best if you specifically ask for that, and if you are as clear and direct as possible about the filtering, conditions.

Related Articles

AI Readiness Checklist for CRM Teams: Is Your CRM System Ready for AI?

Before using AI in Creatio, make sure your CRM data, users, processes, and automation foundation are ready. Use this practical AI readiness checklist for CRM teams.

Build Your Creatio AI Skills with the 2026 AI Summer Program

Join Creatio’s free 2026 AI Summer Program to learn how to identify, build, deploy, and manage AI agents.

Creatio 10x Is Coming: Join the Webinar to Explore the Future of AI-Native CRM

Learn what's new in Creatio 10x and how AI-native CRM, agentic AI, and no-code automation are shaping the future of customer relationship management. Join the upcoming webinar and discover what's next.

Creatio Unlimited Pricing Explained: AI Packages, Costs, Pros & Cons

Learn what Creatio’s new Unlimited pricing model includes, what it doesn’t include, how AI Action packages work, and the pros and cons for businesses evaluating Creatio.

Related Videos