Can't use array functions on arrays stored in globalChannelMap #4542
-
We're trying to store an array of Strings (one-dimensional array) from the Deploy Script to the globalChannelMap, but a code template we're invoking in the Destination Filter isn't able to recognize the object we're pulling from globalChannelMap as an array. We can still pull items from it via index (i.e. $('globalArray')[0] returns the proper value), but we can't use functions like indexOf() as shorthand to check if an element exists in the array. Deploy Script:Assume 'mappedValues' is this String: "F,C,A,P,Verified,Auth (Verified)" (it's stored off-server). We're splitting it into an array, using the comma (',') as a delimiter: During troubleshooting, I put the following code in that Code Template to try and figure out what Mirth is doing. var localArray is just a copy of the same array we stored in the globalChannelMap back in the Deploy Script, just locally scoped to the Code Template that's giving us issues: Destination Filter Code Template:
//Assume var labStatus = 'F' (String) debug1 => 0.0 (first element) We're just trying to use the array from globalChannelMap to perform this type of check on input values:
I've tried seemingly everything to re-cast the object from the globalChannelMap as another type and nothing has worked. We can still reference the global as an array if we specify an index. Object.prototype.toString.call(localArray) ---> [object Array] Main Question:How could we recast the array from globalChannelMap to get it to cooperate with the standard suite of Array functions? Specifically something like indexOf(). Alternatively, could somebody point me to the nearest Mirth documentation for [object JavaArray] and the list of functions it supports? Thank You!! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I slept and figured it out: .split() was returning a JavaArray, so I'm iterating an extra time to shove all the elements into a native (Javascript) array before pushing it to the globalChannelMap.
|
Beta Was this translation helpful? Give feedback.
-
You actually can call all Array.prototype methods on java arrays. Having the wrong value returned by indexOf instead of throwing an exception that the method was not found meant that it was working. The fact that split produced a java array means that you started with a java String, and your resulting array, therefore, contained java Strings because it called the Java version of Changing the first line of your original code should fix it all. Converting mappedValues to a javascript string, means that split will give you a javascript array of javascript strings. labStatusList = String(mappedValues).split(','); |
Beta Was this translation helpful? Give feedback.
I slept and figured it out:
.split() was returning a JavaArray, so I'm iterating an extra time to shove all the elements into a native (Javascript) array before pushing it to the globalChannelMap.
labStatusList = [];
tempArray = mappedValues.split(',');
for each (var item in tempArray) {
labStatusList.push(item);
}