Using Computed columns to create an Email link on a standard ICRM web datagrid

Recently, I had a request to build functionality that would allow a user to send an email based on information in a datagrid row.  Here is an outline of how I put that functionality together.

The form contains a standard datasource/datagrid setup (Note, this does not work with an editable datagrid).  In addition to any other functionality on the form, we also need to add two objects:  A Hidden Text control, and a button on the form.  The Hidden Text field will contain the record ID for the selected record.  The button is what actually triggers the send email process, however we “click” this button via code when using the Custom Format Column.


On Load Action of the Form

Load Action 0 (C# Snippet Action Item)

On Repaint Event = False

The code here builds and registers the javascript both to populate the hidden field, and to actually send the email, via a click event on the tbrButton.

string script;
script = @"function fxsendEmail(email, subject, body) {
Sage.Utility.Email.writeEmail(email, subject, body);
function FXSendMail (id) {
document.getElementById('" + QFHidden.ClientID + @"').value=id;
document.getElementById('" + tbrButton.ClientID + @"').click();

ScriptManager.RegisterStartupScript(this, GetType(), "FXSendEmail", script, true);

Load Action 1 (C# Snippet Action Item)

ON Repaint Event = True

This action is simply used to hide the button we added.  On Repaint event has to be set to true so the button will be hidden on every record.


On Click event of Hidden Button

C# Snippet Action Item:

This code reads the hidden field value (which should be the currently selected record).  This is where the email, subject and Body of the email is created, using a new entity object to get data from selected row and related records.

if (QFHidden.Value != "")
	string recid = QFHidden.Value;
	Sage.Entity.Interfaces.IOpportunityTest ot = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IOpportunityTest>(recid);
	string email = ot.StringField2;
	string subject = recid;
	string body = "This is a test.";
 	string emailbody = Sage.Platform.WebPortal.PortalUtil.JsonEncode(body);

	string script = string.Format("sendEmail(\"{0}\", \"{1}\", \"{2}\");", email, subject, emailbody);

	ScriptManager.RegisterStartupScript(this, GetType(), "FXSendEmail2", script, true);

DataGrid computed column

I’ve added the custom format column, with the Datafield set as Id.  I’ve also defined a Method name, and will create a method with that name in the Format code.


The Code here simply builds a link that displays the value “Email”, and will call the SendMail function for the current ID.

protected string EmailTest(object Id)
	string recid = Id.ToString();
	string script = string.Format("<a href='javascript:FXSendMail(\"{0}\")'>Email</a>", recid);
	return script;

Setting Up Email Body:

The required email fields (Email, Subject and body) are defined on the hidden button created for the form.  Since we are creating an entity object for the selected item in the grid, we can access other information related to that entity.  When building the email body, there are certain formatting standards you will need to follow.  The value “\x0D\x0A” should be used in-string for any CRLF needed in the email body.  For readability in code, it wouldn’t be a bad idea to create each line and then append them together into a single string.  Once the initial string is built, it needs to be Encoded to be used in the email.


if (QFHidden.Value != "")
	string recid = QFHidden.Value; //Get the selected record's ID from the hidden text control
	//Create enity object for selected record, using the ID from the previous line.
	Sage.Entity.Interfaces.IOpportunityTest ot = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IOpportunityTest>(recid);
	string email = ot.StringField2; //This is where I am storing an email address.  Note that I am using the entity object to return value.
	string subject = recid; //I am returning the recordID as the subject line.
	string body = string.Format("{0}{1} \x0D\x0A", "This is a test for record: ", recid); //Initial string
	//Appending items to the initial string.  Note "\x0D\x0A" for CRLF
	body += String.Format("\x0D\x0A");
	body += String.Format("Here is the Opportunity Description: {0} \x0D\x0A", ot.Opportunity.Description);
	body += String.Format("\x0D\x0A");
	body += String.Format("End Of Email");
	body += "\x0D\x0AMore Text Here";
	//This line encodes the value for use in the email.  Skipping this step will not allow the email to be generated.
	string emailBody = Sage.Platform.WebPortal.PortalUtil.JsonEncode(body);
	//Finally, we call the fxsendEmail function that was registered on the load of the form, then we register the function call.
	string script = string.Format("fxsendEmail(\"{0}\", \"{1}\", \"{2}\");", email, subject, emailBody);
	ScriptManager.RegisterStartupScript(this, GetType(), "FXSendEmail2", script, true);

And that’s it!  With this modification, you can add an email link to a datagrid row, and then pull information based on the selected row.

Thanks for reading!


Jason Buss

Jason is a senior application developer with Customer FX.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!