# SQL Bridge Transaction & Custom Module-Exposed Scripts

**URL:** <https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399>\
**Category:** Ignition\
**Created:** [May 2, 2012, 6:50pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399 "2012-05-02T18:50:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [May 2, 2012, 6:50pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/1 "2012-05-02T18:50:21Z")

</div>

I’ve created two modules that expose functionality that I’m leveraging within scripts. I’d like to find a way to leverage this exposed functionality within a transaction. I’m trying to create a transaction such that …

[ul]

1. A tag triggers the transaction to execute
2. A method my module exposes through script will be called, providing a value.
3. The value generated by the method call will be pushed into another tag.  
[/ul]

Just as an initial test, I’ve tried the following …

[ul]

1. Create a script module that def’s a method, performs an import, then returns the results of a call to my method

`
def getUuid():
   import blah.bleh.bluh
   return blah.bleh.bluh.getUuid()`2. Created a transaction and create an Expression Item. Within the Expression/SQL tab, I added a call to runScript() that calls the script module’s method.`runScript("app.module.getUuid()")`  
[/ul]  
When I attempt this, the item has an error when evaluating …

[code]com.inductiveautomation.ignition.common.expressions.ExpressionException: Error executing script for runScript() expression:app.module.getUuid()  
Caused by: Traceback (most recent call last):  
File “expression:runScript”, line 1, in   
File “module:module”, line 2, in getUuid  
ImportError: No module named blah

Caused by: Traceback (most recent call last):  
File “expression:runScript”, line 1, in   
File “module:module”, line 2, in getUuid  
ImportError: No module named blah[/code]  
If it helps, I’m using the addScriptModule() of the ScriptManager to expose things via script, (using RPC).

Thanks!

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [May 9, 2012, 11:23pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/2 "2012-05-09T23:23:21Z")

</div>

That last line got me. How exactly are you adding these to the script manager? From what hook? where?

---

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [May 17, 2012, 2:44pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/3 "2012-05-17T14:44:37Z")

</div>

[quote=“Carl.Gould”]That last line got me. How exactly are you adding these to the script manager? From what hook? where?[/quote]Sorry, just now noticed you responded to this …

Within our classes that extend AbstractGatewayModuleHook, AbstractClientModuleHook & AbstractDesignerModuleHook, we’re overriding the initializeScriptManager() method and calling addScriptModule() …`
@Override
public void initializeScriptManager(ScriptManager manager) {
     super.initializeScriptManager(manager);
     manager.addScriptModule("potato.spuds", new ModuleRpcProxy());
}`Ultimately, I’m trying to call methods from classes within my module using runScript() within a Triggered Expression Item in a transaction.

I was actually playing with this earlier and took our custom modules out of the equation entirely. I created a Script Module app.potato …`
def getSpuds():
     return "SPUDS!"`I created a transaction, added a Run-Always Expression Item and set the expression to …`
runScript("app.potato.getSpuds()")`I got an Evaluation Error. Looking at the Console, the error message was similar to the one I mentioned earlier, just complaining about No module named ‘app’. I tried creating an Expression Tag using this same expression, wasn’t successful. I created a Window, threw on a Label and bound the Label’s Text property to the expression … that worked. So, all that said, I’m assuming that a Script Module just isn’t available within a transaction’s execution scope?

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [May 17, 2012, 4:28pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/4 "2012-05-17T16:28:04Z")

</div>

Hmm, I just did a quick test, creating a custom script and calling from a group, and it was fine. The strange thing is that it’s telling you it can’t find “app”… if I deliberately set my name wrong, it is pretty specific in saying that there is no function by that name.

This is 7.4, right? On your simple test, is your module still trying to load its script modules? I’ll have to track down where app gets loaded and see if there is any conceivable way it could get lost.

Regards,

---

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [May 17, 2012, 5:41pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/5 "2012-05-17T17:41:39Z")

</div>

I just shifted to a different server/install and created the simple example (without my module) … works just fine ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:") … both are running 7.4.2 (b953).

I’ll try to find time to create a simplistic module that illustrates the issue I’m having as opposed to using the full implementation of what I’ve got now, see if I can reproduce the issue … now to find time to actually do that …

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 18, 2012, 2:21am UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/6 "2012-05-18T02:21:43Z")

</div>

Just thought I’d chime in here:

When you load your “potato.spuds” script manager into the ScriptManager, you access it at “potato.spuds”, not “app.potato.spuds”.

---

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [May 18, 2012, 2:49pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/7 "2012-05-18T14:49:58Z")

</div>

[quote=“Kevin.Herron”]When you load your “potato.spuds” script manager into the ScriptManager, you access it at “potato.spuds”, not “app.potato.spuds”.[/quote]Yeah, I’m accessing it with that approach within the Script Module def. The Expression Item’s call to runScript() is referencing the def, that’s where “app” comes into play.

I’ve created two dummy modules and I’m slowly adding to them to see where I’m going astray. So far, I’ve been able to get things working using the code I’ve listed below. Previously, I was making calls using RPC within the Expression Item. If a transaction’s executed on the Gateway, would this cause issues?

com.potato.Tader

[code]package com.potato;

import java.util.Random;  
import java.util.UUID;

public class Tader {

```
public Tader() {}

public static Integer getCount() {
	return new Random().nextInt(100000);
}

public static String getString() {
	return UUID.randomUUID().toString().substring(0, 5);
}

```

}[/code]  
com.potato.hooks.PotatoClient

[code]package com.potato.hooks;

import com.inductiveautomation.factorypmi.application.runtime.AbstractClientModuleHook;  
import com.inductiveautomation.ignition.common.script.ScriptManager;  
import com.potato.Tader;

public class PotatoClient extends AbstractClientModuleHook {

```
@Override
public void initializeScriptManager(ScriptManager manager) {
	super.initializeScriptManager(manager);
	manager.addScriptModule("com.potato.tader", Tader.class);
}

```

}[/code]  
com.potato.hooks.PotatoDesigner

[code]package com.potato.hooks;

import com.inductiveautomation.ignition.common.script.ScriptManager;  
import com.inductiveautomation.ignition.designer.model.AbstractDesignerModuleHook;  
import com.potato.Tader;

public class PotatoDesigner extends AbstractDesignerModuleHook {

```
@Override
public void initializeScriptManager(ScriptManager manager) {
	super.initializeScriptManager(manager);
	manager.addScriptModule("com.potato.tader", Tader.class);
}

```

}[/code]  
com.potato.hooks.PotatoGateway

[code]package com.potato.hooks;

import com.inductiveautomation.ignition.common.licensing.LicenseState;  
import com.inductiveautomation.ignition.common.script.ScriptManager;  
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;  
import com.inductiveautomation.ignition.gateway.model.GatewayContext;  
import com.potato.Tader;

public class PotatoGateway extends AbstractGatewayModuleHook {

```
@Override
public void initializeScriptManager(ScriptManager manager) {
	super.initializeScriptManager(manager);
	manager.addScriptModule("com.potato.tader", Tader.class);
}

@Override
public void setup(GatewayContext arg0) {}

@Override
public void shutdown() {}

@Override
public void startup(LicenseState arg0) {}

```

}[/code]  
Script Module \> app.potato

[code]def getString():  
import com.potato.tader  
return com.potato.tader.getString()

def getInteger():  
import com.potato.tader  
return com.potato.tader.getCount()[/code]

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [May 22, 2012, 11:24pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/8 "2012-05-22T23:24:14Z")

</div>

I’ve lost the thread - what’s going wrong now with the example code you posted?

---

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [May 23, 2012, 12:24pm UTC](https://forum.inductiveautomation.com/t/sql-bridge-transaction-custom-module-exposed-scripts/4399/9 "2012-05-23T12:24:28Z")

</div>

[quote=“Carl.Gould”]I’ve lost the thread - what’s going wrong now with the example code you posted?[/quote]Nothing 🙂

The last code I posted works just fine and will likely be the solution I’ll go forward with. I’m traveling for work now, intend to revisit this next week to see if I can reproduce the original problem I had. I think my problem was initially the functionality I was exposing to scripting via ScriptManager was setup to utilize RPC (was invoked using GatewayConnectionManager.getInstance().getGatewayInterface().moduleInvoke). When I took that out of the equation, my problems went away. I’m going to try re-introducing that back into the Expression Item I’ve got to see if that brings back the initial problems I had. If it does, I’ll provide you guys with further information. If not, I’ll mark this as resolved. Thanks!
