Add merge processor to global merge variables

This is totally a nice to have as there are different ways to solve for this, but I think it would be pretty cool to see in the platform.  The idea is to have a global merge function tag similar to {{#urlEncode}}{{companyName}}{{/urlEncode}} that would handle the skuid.utils.merge() function.  For example:

{{#merge}}{{Body}}{{/merge}} where the body field may have merge syntax in it like:

Hello {{Name}}, here’s what you need to do next on case {{CaseNumber}}.


What this would support is the ability to move contextual template content into data, making it more re-usable and self service.  The best comparison of existing capability is the message template structure in Salesforce behind the Email environment where you can add fields to the subject and message body.  

Where this could get really exciting would be to apply this to a web experience where contextual information is served up from a data store rather than handling it all in the page builder with templates, text components, etc.  Then when there’s a minor text change you can simply update the record and you’re done.  It would effectively enable CMS type extensibility to the platform.

Yes please!

Hi John and Bill, that sounds like a cool idea! We informed our product team about it. Thanks for sharing, your input is appreciated! Regards, Luzie

So I came up with a much easier than expected solution for this, thanks to the Nautilus Notes session last week (http://community.skuid.com/skuid/topics/introducing-the-nautilus-notes). 

You can use Skuid’s Formula API to reference the utils.merge API (and many others) and then in your UI fields you have a simple formula to work with.  In my use case I’m using mergeAsText to take a data field from a model, establish context and then display the merged value on the page.  I also aligned the parameter structure of the API with the formula construction so it lines up with the documentation.  The implication of this is pretty powerful in that you can move the management of dynamic content to data, which gets it closer to the business.  This is similar to email templates that insert a contact name or an account, but way more flexible.  

Here’s how this works:

First, create an inline javascript resource (not a snippet) and add this code:

skuid.formula.Formula (
    ‘mergeAsText’,
    function(mode,template,options,model,row) {
        m = skuid.utils.mergeAsText(mode,template,options,model,row);
        return m;
    },
    {
        namespace : ‘UTIL’,
        numArgs : 5,
        returnType : ‘string’
    }
)

You can get rid of the default code that pre-populates when creating the resource in the page builder and just plop this segment in.  Also setting this up on a master page or a static resource makes this more re-usable.

Then in your model, create a UI only formula field. Note this is sending both strings and objects into the formula script. As documented in the API (https://docs.skuid.com/latest/en/skuid/api/skuid_utils.html), the merge function is expecting strings for the first three parameters (mode, template, options) and objects for the model and row.  Here’s the syntax I’m using for the formula:

UTIL__mergeAsText(‘row’,{{Subject_Detail__c}},’’,{{$Model.Account}},{{$Model.Account.data.0}})

Lastly, in your data record, you put your merge syntax in the actual field, so in this example on the account there would be a field called Subject Detail that would have a value of something like:

“This is something about {{{Account.Name}}} that the {{{Account.Owner.Name}}} should know”

Note that in this setup, I’m only working with one record in the model, so I don’t need to worry about context.  If you are working with a list, you’ll need to work out a solution to establish context for the row.  The {{Record.index}} variable is probably a good starting point, however in a preliminary look, this index value starts at 1, where the {{$Model.ModelName.data.[index]} starts at 0.

This is really cool. Thanks for the good word, John!

John,

Really clever use of the Custom Formula feature!

Thanks for sharing!

Bill