Sidebar

What are parameter maps and how do I use them.

0 votes
651 views
asked Nov 7, 2016 by brandon-w-8204 (33,270 points)

2 Answers

0 votes

Parameter maps are objects that store key-value pairs.

Example

In QIE we use them most commonly to combine like items. (OBX-5 values for  like segments)

Below is a list of basic commands:

// Create parameterMap
var parameterMap = qie.newParameterMap();
 
//Add or update a value in a parameter map
parameterMap.put('key', 'value');
 
//Get a value from a parameter map
parameterMap.get('key');
 
//Check if a value is in the paramter map
if (parameterMap.get('key') === null) {
   //value is not in parameterMap
   qie.debug('do something if the value is not in the map');
} else {
   //value is in parameterMap
   qie.debug('do something if the value is in the map');
}
answered Nov 7, 2016 by brandon-w-8204 (33,270 points)
edited Nov 7, 2016 by terrie-g-7436
0 votes

Just as an example here is a sample JSON message that I will use to create a parameter map and then debug the parameter map keys and values.

Sample JSON:

{
  "attachments": [
    {
      "id": "111",
      "myDoc": "My first document"
    },
    {
      "id": "222",
      "myDoc": "My second document"
    },
    {
      "id": "333",
      "myDoc": "My third document"
    }
  ]
}

Sample Mapping Function:

// Initialize your map
var attachments = qie.newParameterMap();

var docId, myDoc;
// Add keys and values to your map
for (var i=1 ; i <= message.getCount('/attachments') ; i++) {
   docId = message.getNode('/attachments/['+i+']/id');
   myDoc = message.getNode('/attachments/['+i+']/myDoc');
   attachments.put(docId, myDoc);
}

qie.debug('attachments.size(): ' + attachments.size());

// Pull the data we just added back out from your map
var iterator = attachments.keySet().iterator();
while (iterator.hasNext()) {
   var docIdKey = iterator.next();
   qie.debug('docIdKey: ' + docIdKey);

   var myDocValue = attachments.get(docIdKey);
   qie.debug('myDocValue: ' + myDocValue);
}

answered Oct 17, 2018 by michael-h-5027 (14,350 points)
...