Extract Dynamic Substring from MQTT Tag Path in UDT Expression Tag Ignition 8.3.6

I am using Ignition 8.3.6 with MQTT Engine. I have a UDT with a Parameters folder containing tag1 which holds an MQTT tag path like:

[MQTT Engine]Mimics/iotdata/KCW/N-KCW1-CL1-J-PV-CL_471FN7_KW/value
[MQTT Engine]Mimics/iotdata/GCW/W-GCW1-PH1-X-PV-J1P63_X2/value
[MQTT Engine]Mimics/iotdata/NMGD/W-NMGD1-CM1-F-COP-CM_531WF1_FR1/value

What I Want:

I have an Expression Tag called Tag Name inside the UDT. I want it to dynamically extract the device prefix from the path, which is the segment between the plant folder and the second dash:

Full Path Expected Output
.../KCW/N-KCW1-CL1-... N-KCW1-
.../GCW/W-GCW1-PH1-... W-GCW1-
.../NMGD/W-NMGD1-CM1-... W-NMGD1-

The plant folder name (KCW, GCW, NMGD etc.) and device suffix (-CL1, -CM1, -PH1) vary across instances, so the solution must be fully dynamic. Can it be done in ignition?

yes. split and indexOf will need to become your friends. Check those expression functions out, and you should be able to get it worked out.

This is honestly not sustainable and will cause a nightmare further down the line when a site is introduced that does not have the exact same tag pathing.

I would instead add more parameters to the UDT and include a TagName or TagDescription parameter that could then be referenced in an expression tag inside the UDT i.e. {TagDescription}

This is ugly without Phil's Integration Toolkit module.. But here goes

split(split({value}, '/')[3,0]), '-')[0,0] + '-' + split(split({value}, '/')[3,0]), '-')[1,0] + '-'

Or

transform(split(split({value}, '/')[3,0], '-'), value()[0,0] + '-' + value()[1,0] + '-')

Hmm. No one should be without it. I would use:

transform(
    split(
        qvAt(
            where(
                split(
                    parsePath(tag('[.]refTag.sourceTagPath'))[0, 'tag'],
                    '/'
                ),
                it()[0] != 'value'
            ),
            -1,
            0
        ),
        '-'
    ),
    stringFormat(
        "%s-%s-",
        value()[0, 0],
        value()[1, 0]
    )
)

Presumably the UDT parameter will drive the source path for a reference tag. Place this expression tag adjacent to that reference tag.

Robust against varying tree depth, ignores present or absent /value, and varying length elements of the prefix.

I applied your code in my expression tag, but no sucess.

You didn't use my parsePath() function at all. (Not so robust without it.)

Did you install my Integration Toolkit module? Won't work without it. And for some versions of v8.1, a gateway restart is needed for the functions to work in expression tags.

Hi Phil,

Thank you for your response! I am using Ignition v8.3.6. I was not aware of the Integration Toolkit module — that explains why your parsePath() function wasn't working in my case.

Could you please share the download link for the Integration Toolkit module compatible with v8.3.6? I would love to implement your more robust solution properly.

Thanks again for your help and time!

Bottom of this page:

More discussion/history here:

User-contributed material here:

Thanks a lot, your script works after installing the tool.

Thanks your given code worked.