# Using VarMap/GlobalVarMap usage example with Intgegration toolkit?

**URL:** <https://forum.inductiveautomation.com/t/using-varmap-globalvarmap-usage-example-with-intgegration-toolkit/110626>\
**Category:** 3rd Party Modules\
**Created:** [September 15, 2025, 1:00pm UTC](https://forum.inductiveautomation.com/t/using-varmap-globalvarmap-usage-example-with-intgegration-toolkit/110626 "2025-09-15T13:00:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 15, 2025, 1:00pm UTC](https://forum.inductiveautomation.com/t/using-varmap-globalvarmap-usage-example-with-intgegration-toolkit/110626/1 "2025-09-15T13:00:06Z")

</div>

Using Integration Toolkit. Need some help leveraging VarMap and globalVarMap to go from database → class → data on the HMI.

Here’s a example of the object I would like to do it with/load from the database -

```python
create table products (
    name varchar(20) primary key,
    abbreviation varchar(5),
    element varchar(4)
);

insert into products
VALUES ('Nitrogen', 'NIT', 'N2');
insert into dbo.products
VALUES ('Oxygen', 'OXY', 'O2');

```

and the class defined as

```python
class Product(system.util.VarMap):#Instead of smartmap
	def __init__ (self, name, abbreviation, element):
		self.name = name
		self.abbreviation = abbreviation
		self.element = element

```

Then I populate I think like so -

```python
def populateProducts():
	products = system.db.runQuery("SELECT * FROM dbo.Products")
	for (name, abbr, element) in products:
		bvm = system.util.globalVarMap("abbr")
		bvm = schemas.product.Product(name, abbr, element)
		bvm.refresh()
system.util.invokeAsynchronous(populateProducts)

```

Then on my screen I am trying to say access the “element” property of the `globalVarMap({Root Container.abbr})['element']` where `{Root Container.abbr}` is ‘NIT’ but I am not seeing anything come through. I am obviously doing something wrong. Can someone please guide me?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 15, 2025, 1:36pm UTC](https://forum.inductiveautomation.com/t/using-varmap-globalvarmap-usage-example-with-intgegration-toolkit/110626/2 "2025-09-15T13:36:55Z")

</div>

Ok I messed up a bit with my populate code. This works better -

```python
def populateProducts():
    bvm = system.util.globalVarMap("Products")
    ds = system.db.runQuery("SELECT name, abbreviation, element FROM Products")
    for row in ds:
        abbr = row['abbreviation'] # e.g. "NIT" or "OXY"
        prod = schemas.product.Product(row['name'], abbr, row['element'])
        bvm[abbr] = prod # store product under its abbreviation
    bvm.refresh() # notify all bindings using this map
system.util.invokeAsynchronously(populateProducts)

```

Keep all my products under the Products key and then this expression worked

`globalVarMap("Products")[{Root Container.abbr}]['element']`

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 15, 2025, 4:34pm UTC](https://forum.inductiveautomation.com/t/using-varmap-globalvarmap-usage-example-with-intgegration-toolkit/110626/3 "2025-09-15T16:34:18Z")

</div>

Yes, the key given to `globalVarMap()` should be a constant in almost all cases.

Consider reworking your espression as follows:

```python
coalesce(globalVarMap("Products")[{Root Container.abbr}], asMap())['element']

```

That will allow the final lookup to return a null instead of an error if the abbreviation doesn't exist in the globalVarMap (yet).
