A Customer with Advanced Applications for Aliasing in GraphWorX64

We had this question come in recently and I wanted to highlight it, as it makes for an interesting solution that demonstrates some key functionality in GraphWorX64, ICONICS' rich HMI and SCADA data visualization tool. Specifically, the question is this:

“How can I set it up so that when I load a display from an asset selection, I can pass along with it several aliases (e.g., metadata about that asset) that all get merged into a single alias in the display?”

Understanding the Basics on Assets and Aliases

Before I get into the solution, let's first cover the foundation of what we're working with here.

Assets are referring to AssetWorX, which is the module that allows us to build a hierarchical representation of equipment, link related data sources to them, and even assign commands that the user can trigger from that asset. Loading a display related to an asset, as in the question, is one of the most common applications of those commands. Our training videos on Asset Organization cover this in greater detail if you are interested.

Aliasing is a versatile tool in ICONICS applications. Put simply, it allows you to define an "alias name" as a placeholder that you can use in display text, data sources, database connections, alarms, etc. Just about anywhere in the product that you might connect to data, you can use an alias placeholder instead and then define what alias value to use at a later date. Building on the example above, a perfect application for this would be instead of creating "Tank1," "Tank2," "Tank3" and so on with each display hard-coded in its data connection, you could create a single "Tank" display using aliased data connections. Then in runtime, when you load that display, you can pick which connection you want to use, and the display will connect dynamically.

Rationale for Concatenating Aliases

We should also have a look at why we're taking this approach at all. If you simply wanted to have an alias set to the concatenation of those individual aliases, why not just create that in the Load Display command to begin with? Alternatively, anywhere in a display that you might use:


<#MyUnifiedAlias#> 

You could just as well concatenate them manually and use:


<#MyValue1#><#MyValue2#><#MyValue3#>

These are fine approaches and, in many cases, are probably sufficient. However, in this particular case, the display to be loaded is used frequently by a variety of systems within the application, and not all of them will necessarily know the values to be used for all three aliases. In those cases, other commands would only set one or two of these alias values and rely on the remaining aliases to remain the same as they were previously set. Because of this, the user wants the aliases to be concatenated only after the display is loaded.

Fusing Assets and Aliasing Together with Expressions

To start tackling this challenge, I first needed to set up my test environment. You'll have to forgive the simplistic names in the scenario, as I did not have access to the production system and was merely building a minimal proof of concept here. For starters, I built two assets in the Workbench, "Asset1" and "Asset2," each of which had a Load Graphics Display Command that passed along some values for the three aliases we will want to concatenate.
 

Configuration for Asset1 Command


On the GraphWorX64 side, I first built a display frame test that simply has an Asset Navigator and an embedded GraphWorx64 control. Then I built the display to test my aliases, where I put my three alias values individually, as well as the eventual "MyUnifiedAlias" value. The goal here is that I should be able to look at the first display, select an asset from the navigator, and see it pop up in the viewer accordingly.
 

Frame.gdfx and Aliases.gdfx
 

Now, here comes the trick to make it all work. In the embedded viewer (called just "Aliases.gdfx"), I went under the properties for the display itself and edited the "GlobalAliases" field by using the "Data Browser" option in the drop-down. This gives me the full data browser, but I went to the "Expression" tab and entered the following:


x="#MyUnifiedValue="+{{"<#MyValue1#>"}}+{{"<#MyValue2#>"}}+{{"<#MyValue3#>"}}+"/2;"


To understand why this works, let's take a step back and discuss how the aliasing is parsed. Ultimately, if you are to set an alias using this field, a load display command, or the dedicated set global aliases command, you will be passing it a string comprised of the alias value and scope that it will then parse and process. This string is in the following format:


#[AliasName]=[AliasValue]/[ScopeNumber];

For example, if I wanted to set the alias "OPCServer" to "DXP01", my command would have a string such as this:


#OPCServer=DXP01/2;

The reason for the semicolon at the end is so that if you wanted to string multiple aliases together in this command, you can do so, as the semicolon acts as a delimiter.

Lastly, you may be wondering about the "scope" used and what it may mean. In case you are unfamiliar with Global Aliasing using different scopes, put simply it allows you to define the breadth of the windows, applications, and modules of the ICONICS system that will receive the change. Some examples of scope values would be:

  • 0 – ‘Machine’ level, which globally affects all processes your user may have access to.
  • 1 – ‘Process’ level, which affects all instances of the alias within the same process where the alias was set.
  • 2 – ‘Document’ level, which affects only the current display, or the target display being opened.

Following from this information, in our example here we would use "2" as we want the alias to only apply to the current display. This leaves open the option to have multiple instances of this display open simultaneously with different values, if that is appropriate for the project.

All I am doing in the solution above is to construct the string that will be used through an expression, which allows me to include dynamic values within it and have them resolved before the string is parsed. In this case, those dynamic alias inputs are just resolved and lumped together, but I could also use the variety of functions in the expression editor, as well as include other plain text strings in between them in the concatenation.

The result is as intended, that, upon selecting an asset, it will load the embedded display, set the individual aliases, and then set the concatenated alias as well.

Display with Asset1 Selected and Display with Asset2 Selected

Broader Applications for Aliasing in Creating Adaptive Displays

In addition to the solution to the specific problem presented, this approach also has broader applications in GraphWorX64 display interactions. Knowing how to build up the configuration string for setting a global alias can be useful in a lot of situations. This scenario looked at configuring it according to static values, but it works just as well when setting an alias value to the result of some other data source. Personally, I prefer to use this approach when working with parameters to pass to a GridWorX query, as the alias syntax fits well into the parameter settings. It can also be used for multi-level menus, where a user must first select Attribute1 and then be presented with a customized list of options for Attribute 2, and so on. By setting the alias to the result of the first selection, it makes it much easier to customize your lists down the line.

Just a word of caution when using this approach. You should remember that / and ; are special characters in the global alias setting string. If you think that they might appear in the values that you are using to build up your string, then it is a good idea to use the "replace" function to instead use the escape character for those symbols such as:
 

replace({{MyTagName}},"/","&/").


A second thing to consider is whether or not you expect your original aliases to be strings or numbers. While strings should work just fine, if the result is a number (either integer or floating point) then the expression engine will interpret that you want to add those numbers together, not concatenate them. This is a not surprising quirk of the expression parsing, as the ‘+’ symbol can be used for both numerical addition and concatenation but will default to addition when it is ambiguous. If this is a potential risk in your application then just use the “tostring” function to force it to be interpreted as a string:
 

    tostring({{MyTagName}}) 


Hopefully this blog entry has sufficiently described the answer to the originally proposed question, and perhaps answered a few others for you along the way. Be sure to visit this blog often for future responses to common requests/use cases, as well as other interesting info from ICONICS.