Get a channel’s state from code

Tue, Aug 10, 2010 One-minute read

Recently I had a scenario where I needed to know the state of one channel from within another in Mirth Connect. I couldn’t find anything readily available to do this, so I rolled my own Code Template to get the state.

Here’s the code for the template:

function GetChannelState(channel_id) {

    var channel_status = "NA";

    var channel_count = parseInt(;

    for(var i=0;i<channel_count;i++) {
        if (channel_id == {
            channel_status =;

    return channel_status;


So you can now call the function, pass in the channel’s id that you want to check the state on, and you’ll get back one of the following (according to the source file):


If the channel id isn’t found, the function will return an NA (or not available).

You probably already know this, but you can see all of your channel id’s on the channels page in Mirth:

Also, I’m going to try and find a cleaner way to do this eventually… but this worked in a pinch.