Announcement

Collapse
No announcement yet.

JS Reader always return true while checking wether a channel is enabled or not

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • JS Reader always return true while checking wether a channel is enabled or not

    Hi community,

    I use Mirth 3.7.1 on Java 8 and I have three channels without any configuration except:
    • Channel1 ==> is enabled
    • Channel2 ==> is NOT enabled
    • Channel3 ==> is enabled

    And I have a channel called "SelfTest" with a JavaScript Reader.
    Here is my code:
    Code:
    var client = new com.mirth.connect.client.core.Client("https://127.0.0.1:8443");
    client.login("admin", "admin");
    var allChannels = client.getChannels(null);
    
    for (i=0; i<allChannels.size(); i++) {
        var oneChannel = allChannels.get(i);
        var isEnabled = oneChannel.getExportData().getMetadata().isEnabled();
        logger.debug( oneChannel.getName() + ": " + isEnabled);
    }
    
    return;
    The problem is that I always get true for the var isEnabled. Log looks like this:

    Code:
    [2019-07-31 04:01:11,868]  DEBUG  (js-connector:?): Channel1: true
    [2019-07-31 04:01:11,867]  DEBUG  (js-connector:?): Channel2: true
    [2019-07-31 04:01:11,864]  DEBUG  (js-connector:?): Channel3: true
    [2019-07-31 04:01:11,861]  DEBUG  (js-connector:?): SelfTest: true
    What's going wrong here? Is there another way to figure out wether a channel is enabled or not?


    Thanks in advance
    André

  • #2
    I don't think all of the export data is added automatically when you call getChannels. The default enabled flag for the default metadata for the default export data is true.

    It looks like you can call client.getChannelMetadata() to get a metadata map for all of the channels, then you can look up your channelId in the map.

    This is untested, but I think something like this should work.

    Code:
    var client = new com.mirth.connect.client.core.Client("https://127.0.0.1:8443");
    client.login("admin", "admin");
    
    var metadata = client.getChannelMetadata();
    
    for (var channel in Iterator(client.getAllChannels())) {
        var isEnabled = metadata.get(channel.getId()).isEnabled();
        logger.debug(channel.getName() + ": " + isEnabled);
    }
    The Iterator() function I'm calling is a Rhino method that takes a Java object that implements the Iterator or Iterable interfaces (which List does) and converts it to a javascript iterator for cleaner for-each style looping.

    Comment


    • #3
      It works great! Thank's a lot!

      Greetings - André

      Comment

      Working...
      X