Hi,
I have built a nice little lookup table utility which reads values into drop down lists from txt files.
As I will use this from many different locations I was wondering whether there is a way to "store it in the system" so that I only have to call a function to receive the list.
Thank you
Ariel
Calling package script functions from script expressions
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Calling package script functions from script expressions
Lookup globalData in scripting manual
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
Calling package script functions from script expressions
Thanks for the hint.
I looked at it but I am not sure that I understand how to upload functions as global data.
Do have a code sample for it?
Thanks
Ariel
I looked at it but I am not sure that I understand how to upload functions as global data.
Do have a code sample for it?
Thanks
Ariel
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Calling package script functions from script expressions
Using scripting you can set a value
s.setGlobalData( "uniqueName", "tagName", "value", true );
and read it back
var value = s.getGlobalData("uniqueName", "tagName" );
s.setGlobalData( "uniqueName", "tagName", "value", true );
and read it back
var value = s.getGlobalData("uniqueName", "tagName" );
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
Calling package script functions from script expressions
2 questions:
1. Where do I call the initialization of the global data
2. Can I store only flat strings or also functions or lists
Thanks
Ariel
1. Where do I call the initialization of the global data
2. Can I store only flat strings or also functions or lists
Thanks
Ariel
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
Calling package script functions from script expressions
Could you please have a look at the code - something I miss. It stopped working after I added the globalData parts
Thanks
Ariel
var tblPath = "d:/Switch/configurations/tables/";
var tblName = "product_types";
var tblExt = ".tbl";
var tblFile = new File(tblPath+tblName+tblExt);
var list = new Array;
tblFile.open(File.ReadOnly);
var hdrline = tblFile.readLine();
do {
var line = tblFile.readLine();
var cols = line.split(",");
var pType = s.getGlobalData( "c-copy.co.il", cols[1] );
if ( typeOf(pType) != "undefined" ) {
s.setGlobalData("c-copy.co.il",cols[1], pType + ";" + cols[0]);
}
else {
s.setGlobalData("c-copy.co.il",cols[1],cols[0]);
}
list.push(cols[0]);
} while (!tblFile.eof);
tblFile.close();
list;
Thanks
Ariel
var tblPath = "d:/Switch/configurations/tables/";
var tblName = "product_types";
var tblExt = ".tbl";
var tblFile = new File(tblPath+tblName+tblExt);
var list = new Array;
tblFile.open(File.ReadOnly);
var hdrline = tblFile.readLine();
do {
var line = tblFile.readLine();
var cols = line.split(",");
var pType = s.getGlobalData( "c-copy.co.il", cols[1] );
if ( typeOf(pType) != "undefined" ) {
s.setGlobalData("c-copy.co.il",cols[1], pType + ";" + cols[0]);
}
else {
s.setGlobalData("c-copy.co.il",cols[1],cols[0]);
}
list.push(cols[0]);
} while (!tblFile.eof);
tblFile.close();
list;
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Calling package script functions from script expressions
ArielRauch wrote: 1. Where do I call the initialization of the global data
write a separate flow to initialize the values
ArielRauch wrote: 2. Can I store only flat strings or also functions or lists
any JS object can be converted to/from a string
write a separate flow to initialize the values
ArielRauch wrote: 2. Can I store only flat strings or also functions or lists
any JS object can be converted to/from a string
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Calling package script functions from script expressions
var tblPath = "d:/Switch/configurations/tables/";
var tblName = "product_types";
var tblExt = ".tbl";
var tblFile = new File(tblPath+tblName+tblExt);
var list = new Array;
tblFile.open(File.ReadOnly);
var hdrline = tblFile.readLine();
do {
var line = tblFile.readLine();
var cols = line.split(",");
var pType = s.getGlobalData( "c-copy.co.il", cols[1] );
if ( pType.length != 0 ) {
s.setGlobalData("c-copy.co.il",cols[1], pType + ";" + cols[0]);
} else {
s.setGlobalData("c-copy.co.il",cols[1],cols[0]);
}
list.push(cols[0]);
} while (!tblFile.eof);
tblFile.close();
list;
typeof was used incorrectly and getGlobalData returns empty string if not defined.
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
Calling package script functions from script expressions
You are the man! Thank you very much.
Due to your previous answer I can build a initialization flow and load all the lookup table in memory.
In the script expression of the metadata field I only need to catch and decode the string.
Is it possible to store a routine in global data and to execute it dynamically?
Due to your previous answer I can build a initialization flow and load all the lookup table in memory.
In the script expression of the metadata field I only need to catch and decode the string.
Is it possible to store a routine in global data and to execute it dynamically?
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Calling package script functions from script expressions
ArielRauch wrote: Is it possible to store a routine in global data and to execute it dynamically?
no
no