Jump to content

How do I loop through multiple marked rows to extract values from 2 separate columns and assign each to 2 related document properties


Eric Phillips

Recommended Posts

I have a script below that works fine when only marking 1 row. However, when I mark more than one row, my document properties only get set to the last one selected. The document properties are set to update a stored proceduce when changed. In turn, I'd like to be able to select multiple rows and have it iterate through each row which would change the document properties and ultimately the stored procedure. The end result would be multiple rows (those that are marked at the time of running the script)being added to my SQL Server table. Below is the script that works for only 1 row marked.

Thank you in advance for any insights/support you can provide.

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Application.Scripting import ScriptDefinition

#Get the current User

#from System import Environment

#username from webplayer or client

from System.Threading import Thread

# Reload all data in all tables

import time

import sys

import clr

UserID = (Thread.CurrentPrincipal.Identity.Name )

#Get Data Table Values (AccountNumber & Status)

#Set current dataTables

dataTable = Document.Data.Tables["OPI_VIZ_CENSUS - Sheet1"]

# Create a cursor and set variables for the table column to get the values from - These are the two columns I am trying to grab data from

Status=DataValueCursor.CreateFormatted(dataTable.Columns["Status"])

AcctNum=DataValueCursor.CreateFormatted(dataTable.Columns["Acct"])

#Identify Marked records in table

mymarkedrow=Document.ActiveMarkingSelectionReference.GetSelection(dataTable)

#Marked Data Results

markedData = List[str]()

# Iterate through the data table rows to retrieve the marked row

for row in dataTable.GetRows(mymarkedrow.AsIndexSet(),Status):

StatusValue = Status.CurrentValue

if StatusValue != "Y":

StatusValue = "Y"

else:

StatusValue = "N"

for row in dataTable.GetRows(mymarkedrow.AsIndexSet(),AcctNum):

AcctNumValue = AcctNum.CurrentValue

#Set SP Link Parameters Here - These are the document properties that are linked to my stored procedure

Document.Properties["AcctNum"] = AcctNumValue

Document.Properties["Status"] = StatusValue

Document.Properties["UserID"] = UserID

#ReloadLinkedData

Document.Data.Tables.ReloadLinkedData()

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...