JavaScript can be used to create a Toolbar Label at any time in a Workflow, and allows more flexibility to include dynamic parameters or control when a Label is created.
The toolbar to display the label on: top, or bottom. Defaults to top.
row
Optional
Which toolbar row to display the label on. If toolbar is set to top, this defaults to 1. If toolbar is set to bottom, this defaults to -1.
name
Optional
The unique reference of the label, to allow for modification/removal later. If a name is not specified, one is generated automatically.
Example:
Script.Labels.Add(
"Caller Name: " + [var_csCallerName],
"top",
-1,
"customerName"
);
Alternate Syntax
Since many of the arguments for the above syntax are optional, there is an alternate syntax where a JavaScript object is passed instead. This means that only the desired optional parameters need to be passed:
Script.Labels.Add({
text: "Caller Name: " + [var_csCallerName],
name: "customerName"
});
Any optional parameters that are omitted will use their default value, as stated in the above table. As this is a JavaScript object, the order in which the parameters are listed in this alternate syntax doesn't matter, as long as the key:value pairs are preserved.
Notes
As multiple duplicate Toolbar Labels can be created if a name isn't specified, it is advised that caution is used if this function is invoked in a Calculate Field, due to the way that Calculate Fields will run every time a field is selected or action is taken.
Both Fields and Variables can be used in the parameters to allow dynamic content. Be aware that to use a combination of dynamic and static text requires treating the Fields or Variables as string fragments to be assembled.
As the function returns the name of the created Label, it's possible to close the Label later even without a name defined:
var myLabel = Script.Label.Add("myText");
if (myCondition == "yes") { Script.Label.Remove(myLabel); }