Question
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Pegasystems Inc.
JP
Last activity: 6 Nov 2018 20:02 EST
Pega Robotics Studio 8: setting variables from within script
I want to set automation variables from within a script similar to in the attached diagram, but I get the error "The name 'xxx' does not exist in the current context". How would I define variables so that they can be seen both from the automation and the called scripts within? I would rather not pass values via parameters or return values as the reason I would like to do this within a script is there are going to be possibly several hundred variables to set.
More generally, where can I get examples of scripts? The examples in Online Help are extremely limited.
http://help.openspan.com/80/Components/How_to_Use_the_Script_Component.htm
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
Pegasystems Inc.
US
Use the lookup table component. You can define the table on the component. It is based on the System.Data.DataTable and has methods for working with the table. You can also use the GetTable and ReplaceTable methods to extract or replace the entire table. Here is a link to the help on that.
http://help.openspan.com/80/Components/Lookup_Table.htm
If you are reading this from a spreadsheet you can also use the Excel connector Export function. This creates a DataTable from your data. One of the methods has the option to use the first row to create column names. This is probably better suited to your need if the data is in a spreadsheet to begin with.
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
Pegasystems Inc.
US
A script container is like a Dll. It can't see outside of itself - only parameters that are being passed in. The way I get around this is to use a data table to hold name/value pairs and I pass it by reference into the script container.
You can write anything you want in a script and methods within the script container can call other methods in the same script container.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Pegasystems Inc.
JP
Hi Jeff,
thank you for your reply.
Are there any examples on how to declare, assign and access data tables on both the script side and the automation side?
Just to add some information about what I ultimately want to do: our customer wants to read, say, 20 columns x 60 rows into variables for processing. While this is possible in an automation it is very cumbersome and slow - and is very easy in C# if only I can find a way to pass it back. Then there is the issue of leading zeros (posted by my colleague Moritaka, which I believe you also replied to), which will automatically be a non-issue in C#. If you can think of a third way which hasn't occurred to us do please enlighten.
Incidentally, right now we are assigning the values to 120 variables which we define. We would really like to be able to assign it to a two dimensional array instead - I posted this also and I understand this isn't possible. Any ideas extending to this would be ideal!
Thanks and regards, Michael
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Accenture
PH
Hi Jeff,
How to pass the DataTable by reference into the script container?
As I am trying to use a datatable as input parameter into a script
this error shows up: "'DataTable' does not contain a definition for 'AsEnumerable' and no extension method 'AsEnumerable' accepting a first argument of type 'DataTable' could be found (are you missing a using directive or an assembly reference?)"
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
Pegasystems Inc.
US
What are you trying to do with the DataTable in your script? Have you added a reference to System.Data and a using for System.Data to your script?
Accepted Solution
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
Pegasystems Inc.
US
Use the lookup table component. You can define the table on the component. It is based on the System.Data.DataTable and has methods for working with the table. You can also use the GetTable and ReplaceTable methods to extract or replace the entire table. Here is a link to the help on that.
http://help.openspan.com/80/Components/Lookup_Table.htm
If you are reading this from a spreadsheet you can also use the Excel connector Export function. This creates a DataTable from your data. One of the methods has the option to use the first row to create column names. This is probably better suited to your need if the data is in a spreadsheet to begin with.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Pegasystems Inc.
JP
Hi Jeff,
when you say the "Excel connector Export function", are you referring to the "ExportData" method of the MicrosoftExcel connector? If so, I can't figure out how to specify the path and name of the file which I want to open (the parameters are "cellStart", "cellEnd" and "createHeader").
Also, I couldn't figure out how to feed the results into "GetTable" (it doesn't have an input port for data) although the "ReplaceTable" method worked.
Thanks and regards,
Michael
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-05/1f77a272-b558-4261-964a-0a7d028c27c5.jpg?h=436c2321&itok=Ilx-4hBN)
Pegasystems Inc.
US
Hi Michael,
Yes - I am referring to ExportData. To load a spreadsheet into the connector use the Open method fir then you can use ExportData. See my post Excel How-To for some more help on working with Excel. I will add another post there soon describing exporting data.
On the Lookup Table component, GetTable is used to get a copy of the underlying datatable and ReplaceTable is used to overwrite it with a new datatable. So, you go from Excel.ExportData to LookupTable.ReplaceTable. It is very important to note that the schema of the incoming table on ReplaceTable must match exactly how the Lookup Table is defined or you will get unexpected results.
Jeff
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Evonsys
AU
Hi All,
I have lookup table with more than one records and I need to pass those values PRPC application. How can I achieve this scenario.