Jump to content

How to writeback multiple lines using iron python


Manmohan Agrawal 3

Recommended Posts

I have a requirement where I need to insert multiple lines through a single click to database. I am using an Information link where in pre-updates I have written a "Insert into" SQL and passing on parameters through on-demand data table.

I have written a Iron-Python where in for loop it will iterate over all rows of table and when the condition is met it should refresh on demand data table which in return should insert into DB.

Consider Data set as shown below

table1

----------

column1 column2

No A001

Yes A002

Yes A003

Yes A004

------------------------------------------------------------------

Script as below

------------------------------------------------------------------

from Spotfire.Dxp.Data import DataValueCursor

table1=Document.Data.Tables["table1"]

InsertToDBTable=Document.Data.Tables["table2"]

Column1 = DataValueCursor.CreateFormatted(table.Columns["Column1"])

Column2 = DataValueCursor.CreateFormatted(table.Columns["Column2"])

Counter=0

ErrorMsg=""

for row in table.GetRows(Column1, Column2):

if Column1.CurrentValue=="Yes":

Document.Properties["prop1"]=Column2.CurrentValue

Document.Properties["prop2"]=Column2.CurrentValue

InsertToDBTable.Refresh()

Counter=Counter+1

print Counter

-----------------------------------------------------

As an outcome it prints 3- because Counter value is 3, it insert 3 rows of data into database(sometimes 2 rows and 1 row as well) all of them with "Yes A004" value. It is not inserting any row for "Yes A002" or "Yes A003".

Any help

Link to comment
Share on other sites

Hi! A couple of things that might cause the issues:

Here's an example of that uses only one cursor, but I think it worls the same with multiple cursors:

https://community.spotfire.com/s/article/How-to-read-Column-Values-in-TIBCO-Spotfire-Using-IronPython-Scripting

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...