Method Community

 

Email template merge fields: how does it determine table/active record?

Last post 04-18-2012 11:08 AM by Anonymous. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-12-2012 6:17 PM

    Email template merge fields: how does it determine table/active record?

    Tell me if I'm right: the merge fields use the active record ID for the current screen/table the template is loaded into. It seems to also know that when I reference fields from the "User" table, that I want the record of the User currently logged in. 

    Is there a way to indicate to the template/merge field what recordID I want to reference for a given table? 

    I'm setting up my system so all outgoing method emails are going through the activity screen, including order reports like Invoices and POs. When I open an email popup from the PO screen, for example, I only insert the PO RecordID  into the Activity Table (for the sake of generating the report). What if I want to reference the Vendor name in the email template?

    Do I need to create a field in the Activity table for the Vendor name, and every other field I will want to use in my various email templates? Or can I reference a specific recordID for a given table in the merge field code in the template itself?

  • 04-13-2012 11:43 AM In reply to

    Re: Email template merge fields: how does it determine table/active record?

    smohyee:
    ...the merge fields use the active record ID for the current screen/table the template is loaded into.

    The merge is not always based off active RecordID.  Replacing merge fields relies on the Character Function action, specifically the option Replace <<merge>> fields.  Take a look the action and you’ll see one of the parameters requires the designer to specify or Locate using RecordID.  This is basically asking which record you want to use to replace the merge fields and can be done many ways including Retrieve Value From Table calls.

    Have a look at the New Activity screen under the Send An Email section inside the Choose Template dropdown actions.   You'll see how the email template for Overdue Balance contains merge fields from multiple tables.

    One important tip for you is to use only one character function to replace merge fields per table.  For example, if you have 5 merge fields coming from the customer table,  one action will replace 5.  However, you must a separate character function for merge fields coming from other tables.

    The email templates are quite powerful but a little tough to get a grasp on initially.  Have a look at the action set I mentioned above and you should have enough knowledge to go on.

    ~C

  • 04-13-2012 12:59 PM In reply to

    Re: Email template merge fields: how does it determine table/active record?

    Thanks Chad, just the sort of thing I was looking for!

    I checked out the examples of the merge field suboption of the character function action. So if I understand this correctly, if I type in "Vendor" into the "replace from table"  field, and put my desired Vendor record ID as an Action Result in the next field, then the function will go lookup every merge field in my template referencing the Vendor table (Vendor.FullName, Vendor.BillCity), and replace it with that particular record's data. 

     

    Or, as another example: If I want to email a Purchase Order PDF to a vendor in the New Activity screen, the only field I need to add to the Activity table would be for the PO Record ID (since  I use that screen to send all my order reports, I call it "RelatedRecordID", and I have a second field for "RelatedReportType" to specify that its a Purchase Order record). 

    Then I can create a conditional statement in the Choose Template action list in the New Activity screen saying that if the RelatedReportType is "Purchase Order", then grab the RelatedRecordID as an AR, and use the character function to specify that every PurchaseOrder merge field in the template should reference that RecordID. That way I can get the right vendor name (presumably all the preexisting "entity" based actions in that list wouldn't work, because there's no way for them to know that by "Vendor" I mean the preferred vendor selected for my PO...)

     

    I notice in the preexisting merge field actions in the New Activity screen, the email body is loaded into an AR and then referenced. Is there any particular reason why it is used as an AR, instead of just pointing to the email body "Value on Screen"?

  • 04-13-2012 2:36 PM In reply to

    Re: Email template merge fields: how does it determine table/active record?

    Answer

    smohyee:
    ...if I type in "Vendor" into the "replace from table"  field, and put my desired Vendor record ID as an Action Result in the next field, then the function will go lookup every merge field in my template...

    Correct.  Method is quite clever with the merge function!  When you use the Character Function to merge fields you only need to specify the table and a recordID - Method with then replace any merge fields with the correct information from that record (provided the information exists).

    smohyee:
    ...the only field I need to add to the Activity table would be for the PO Record ID...

    Exactly.

    smohyee:
    I notice in the preexisting merge field actions in the New Activity screen, the email body is loaded into an AR and then referenced. Is there any particular reason why it is used as an AR, instead of just pointing to the email body "Value on Screen"?

    There are multiple Character Merge's going on with this page (which is why I wanted you to have a look).  Basically, the entire body is loaded in the AR then run through several merge's, one for each table.  I believe I gained 10 Method IQ points today digging into this screen for your question.

    Thanks for the question!

    ~C

  • 04-13-2012 5:46 PM In reply to

    Re: Email template merge fields: how does it determine table/active record?

    Thanks for looking into it! I assume running through the AR is more resource efficient than running through the value on screen when used by multiple functions. It's useful to know that sort of optimization, since Method's speed is an issue.

    I wonder if that's a universal rule for Method optimization: "When using multiple actions involving a piece of data, it is better to load that data into an Action Result than reference it's value on the screen" 

  • 04-18-2012 11:08 AM In reply to

    Re: Email template merge fields: how does it determine table/active record?

    smohyee:
    I assume running through the AR is more resource efficient than running through the value on screen when used by multiple functions.

    Using the AR might be a little more resource efficient but the biggest reason for using an AR is code reuseability.

    ~C

Page 1 of 1 (6 items)