Salesforce

How Do I Handle a Collection in a COM Object? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Handle a Collection in a COM Object? (Magic xpa 3.x)

A collection object is a list of items, such as “recently used files”, “Zip codes”, or in this instance, “languages”.

The list must contain a unique identifier, which can either be:

  • an Index, which is a sequential number from 1 to the number of items in the list.

  • a Key, which is any string or number that uniquely identifies this item in the collection.

Each collection will contain either an index or a key, but not both. In the example above, the languages list from Microsoft Word contains only a key type of ID. This makes it difficult to extract the entire list, because you don’t know in advance what the IDs are.

Fortunately, Magic xpa solves this problem for you by providing a special method for collections called MgItemSequential. This method isn’t part of the native object, but appears on the method list with all the other methods. It allows you to fetch each item in the list using an index from 1 to the number of items. Once the items are in a table, as shown above, you can use them as you would any table in Magic xpa.

The example below fetches the list of supported languages from Microsoft Word.

Fetching a Collection

  1. First, determine the size of the entire collection. In this example, there is a method in Word Application.Languages object called Count, which gives us the total number of languages. This is used in the End Task Condition so we loop until we have fetched the entire list of languages.

  1. Then, for each item in the list, use the MgItemSequential method to fetch the item. MgItemSequential does not exist in the native object, but you will see it on the COM Automation Selection list.

    The return parameter returns an object, which in this case is the Word Application.Language object.

  1. Now, use the object returned by MgItemSequential to fetch the properties of the object. In this case we fetch the ID and the Name, which we store in our table.

Once the task is done, we will have the collection stored in a Magic xpa table, ready for use.

Reference
Attachment 
Attachment