# ScriptManager.runScriptFunction() example

**URL:** <https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667>\
**Category:** Module Development\
**Created:** [March 6, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667 "2023-03-06T13:19:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanduri.shouri](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kanduri.shouri](https://forum.inductiveautomation.com/u/kanduri.shouri)\
**Post date:** [March 6, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667/1 "2023-03-06T13:19:50Z")

</div>

Hello,

My main aim is to use python system functions and make a module according to our application.

I am trying to extract tag historian Data through SDK module programming.  
I have taken managed-tag-provider example provided by the SDK as my skeleton project and trying to run ignition's system functions through scriptManager.runFunction().  
I am stuck with trying to implement the mentioned function.  
Here is the code which i have tried:

public List\<Map\<String, Object\>\> getTagHistory(String tagPath, Date startDate, Date endDate, int returnSize) {  
String functionName = "system.tag.queryTagHistory";  
Map\<String, Object\> args = new HashMap\<\>();  
args.put("paths", new String { tagPath });  
args.put("startDate", startDate);  
args.put("endDate", endDate);  
args.put("returnSize", Integer.valueOf(returnSize));

```
    result = script.runFunction(functionName , args);

    return (List<Map<String, Object>>) result;
}

```

script is a global instance of ScriptManager.

I am getting this error : **Cannot resolve method 'runFunction(String, Map\<String, Object\>)'**

I understood the method signature is different. But I am not able to implement this function.  
Any example on how to use this method would be really helpful.

Regards,  
Shouri

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 6, 2023, 6:39pm UTC](https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667/2 "2023-03-06T18:39:11Z")

</div>

> [@kanduri.shouri](#):
>
> I have taken managed-tag-provider example provided by the SDK as my skeleton project and trying to run ignition's system functions through scriptManager.runFunction().

Why?

You can directly access the SDK and do what you need to, without the overhead of translation to and from Jython objects.

> [@tagHistory in SDK module](https://forum.inductiveautomation.com/t/taghistory-in-sdk-module/68933):
>
> Hello, I am developing a script to make a query in the database from the SDK module, in designer script I use system.tag.queryTagHistory to get the dataset, but I can't find the function to get the dataset from java, would there be any way to make that query? thank you

---

<div class="post-metadata">

**Author:** ![kanduri.shouri](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kanduri.shouri](https://forum.inductiveautomation.com/u/kanduri.shouri)\
**Post date:** [March 7, 2023, 4:48pm UTC](https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667/3 "2023-03-07T16:48:09Z")

</div>

Hi,  
Thanks for your reply. I had changed my plan from using Jython to Java and though I am not getting any errors but tag history is returning only 1 row. As I was checking for rowCount() in the logger, Though it logged so many values in the span of 5 minutes on change, but the function only logged 1 as the getRowCount() result in the gateway logs.

Function:  
public void getTagHistory(String tagPath, Date startDate, Date endDate) throws IOException {

```
    BasicTagHistoryQueryParams params = new BasicTagHistoryQueryParams();
    logger.info("startDate : " + startDate);
    logger.info("endDate : " + endDate);

    List<String> tagPaths = Arrays.asList(tagPath);
    List<Path> paths = new ArrayList<>();
    for (String tP : tagPaths) {
        Path path = null;
        try {
            path = TagPathParser.parse(tP);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        paths.add(path);
    }

    params.setPaths(paths);
    params.setStartDate(startDate);
    params.setEndDate(endDate);

```

// params.setAggregationMode(AggregationMode.SimpleAverage);  
// params.setReturnFormat(ReturnFormat.Wide);

```
    BasicStreamingDataset dataset = new BasicStreamingDataset();
    tagHistory.queryHistory(params,dataset);
    logger.info(dataset.getRowCount());
    logger.info(dataset.getValueAt(0,1));

}

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/7977110cfae4fc18600233ff7d87cf9c90c315ca.png)

This function is called in startup lifecycle event with required params.

If I add returnSize param of BasicTagHistoryQueryParams to 1000:

Though I am getting rowCount as 1000 . they are all the same values without change.  
When we configure tagHistorian, we configure the data to be logged into database only when the tag value is changed. However, i am finding all the values upto some rows are the same.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/8/489fc7abdab9c9aac7b38132b21b3f6f08119d7f.png)

---

<div class="post-metadata">

**Author:** ![kanduri.shouri](https://avatars.discourse-cdn.com/v4/letter/k/919ad9/32.png) [@kanduri.shouri](https://forum.inductiveautomation.com/u/kanduri.shouri)\
**Post date:** [March 14, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/scriptmanager-runscriptfunction-example/70667/4 "2023-03-14T15:15:37Z")

</div>

Hi,  
It is working now. I have used java methods instead of Script Manager. Thanks for the help.
