Login    Sites MenuBlueStep

BlueStep Platform Support

RelateScript
Outline full outline 
Overview 
Data Types 
Operators 
Statements 
Functions 
Working with Relate Data 
Field Data 
Accessing Forms and Fields 
Special Data and Functions 
System Data 
getDocumentLibrary(...) 
getMergeTag(...) 
getRecordNav(...) 
The transaction Object 
How Formulas Work 
Related Topics 

The getMergeTag(...) function has two variations, not counting syntax variations. It allows a formula to dynamically create merge-tags which can then be inserted into a merge-report via a formula result and be expanded into their full format.  This allows data to be brought into the current merge-report layout which would otherwise be difficult or impossible, including the possibility of editing data from multiple records on one page.  It also allows data, including editable data, to be inserted conditionally depending on the outcome of complex decision logic.

There are a few important limitations to keep in mind:  First, the merge tags can be generated by any formula, but they will only be expanded to their full format if inserted into a merge report via a formula result.  Second, merge tags cannot be generated for anything which is not actually saved in the database.  You can't generate merge tags for entries that are in the process of being created, nor for any fields on those entries.  There is, however, an exception to this limitation:  If the merge tag is for a single entry form (or field on a single entry form) and the record itself has been stored, then a merge tag can still be generated even if the form has never been completed and stored.

Merge tags for fields can only be generated once per page. If you try and call a merge tag multiple times, Relate will only render code for the first instance, the rest showing up as [No Data]. This problem often happens when including a merge report on a form, where both the merge and the form are trying to display a field from the form. Another seemingly innocuous situation is console.log. If you console log a merge tag, you'll have to deactivate the logging to get the code to show on the page. This is because Relate is run server-side and treats all JavaScript, HTML, etc. as simple string data, not code.


Syntax:
getMergeTag( relate-element )
getMergeTag( relate-element, options )
relate-element.getMergeTag( )
relate-element.getMergeTag( options )

Parameter Description
relate-element

This is a Relate field, form entry, multi-entry list, navigation element (from the getRecordNav function) or merge-report object (from getMergeReports() on the System field).  A merge tag for a field shows the field value, label, hint, edit-field or validation image.  A merge tag for a form entry shows the generic layout for that entry.  A merge tag for a multi-entry list displays the full multi-entry report.  A merge tag for a navigation element displays differently for different types of elements as follows:  merge reports insert the merge report, single-entry forms insert the generic layout, multi-entry forms insert the default multi-entry list for the form, wizards and folders do not produce a merge-tag.  See the examples for further detail.  A merge tag for a merge-report object displays the merge-report for a specific form entry.

options

Some merge-tags have multiple variations.  In particular, field merge-tags variations are: view-only, label, hint, editable field and validation image.  The option codes for these are "" (or none/null), "L", "H", "F" and "I" respectively.  NOTE: The "I" validation image should only be used with the "F"-Editable Field. More than one code may be passed and multiple tags generated simultaniously.  For instance it is common to put the validation image immediately before or after the editable field.  The option code to generate both merge-tags at once would be "FI" if you wanted the editable field first.

All of the following examples assume a merge-report formula with formula ids defined as follows:

  • "meds" is a list of prescribed medications in the current record with fields "name" and "medType" among others.
  • "mars" is a list of medication administration records in the current record with fields "medId", "schedTime", "sig" and "bloodSugar" among others.
  • "cur" is the current medication administration record.
  • "residents" is a query of all residents with the same formula ids defined within the query as for the current record ("meds" and "mars").

The examples all assume that the results contained in the "output" variable will be inserted at an appropriate location within the layout on step 4 of the merge-report edit wizard.

Example:  Shows how to include the "bloodSugar" field on the medication administration record of only diabetic type medications:

med = meds.getById(cur.medId);
output = "";
if (med.medType == "diabetic") {
    output = cur.bloodSugar.getMergeTag("L") + ": " + cur.bloodSugar.getMergeTag("FI");

Example:  Shows how to edit all unsigned MARs for the current medication, not just the MAR selected.

mars.addSearch("medId", "=", cur.medId);
mars.addSearch("sig", "d=", null);
output = "";
for (i, m in mars) {
    if (mar.System.id != m.System.id) {
        output += '<div>' + m.getMergeTag() + "</div>";
    }
}

Example:  Shows how to list all previous administrations of the current medication recorded in the past 7 days, but only if there was at least one administration.

mars.addSearch("medId", "=", cur.medId);
mars.addSearch("sig", "d>", curDateTime().calc("-P7D"));
mars.rememberSearchAndSort();
output = "";

if (mars.size() > 0) {
    output = mars.getMergeTag();
}

Example:  Shows how to simultaniously edit the not-signed MAR records of all patients having the same schedule as the current MAR.

output = "";
while (residents.hasNext()) {
    res = residents.next();
    res.mars.addSearch("schedTime", "=", cur.schedTime);
    res.mars.addSearch("sig", "d=", null);
    
for (i, m in res.mars) {
        output += '<div>' + m.getMergeTag() + '</div>';
    }
}