How do I append to a grid variable without it being wiped out every time the python scrip runs.
Hi @Suhayr, after catching a glimpse of an earlier post, I wanted to give you some advice that I learned along the way. Only use Jython as an absolute last resort. Jython is based on Python 2 which means only Python 2 functionality is available to you while using it. The fact that Jython hasn't been updated to Python 3 yet should make you nervous about it's future.
With that said here is an example of how to append to a grid variable using Python when it's attached to an iterator:
# Get the current grid variable values and store them in a local variable
gv = context.getGridVariable('Your_Grid_Var_Name')
# If the Grid Variable is empty (None) then we will intantiate gv with an empty list that we will add to
if gv == None:
gv = []
# Assuming your gridvariable has 4 columns and they are in the following order:
# database, schema, table, table_row_count
# Create a list of values that match the order defined in your grid variable
new_grid_var_row = ['my_database', 'my_schema', 'my_table', '5']
# Append the row of values we just created to our local variable
gv.append(new_grid_var_row)
# If rows were appended then update the Matillion GridVariable using our local variable
if gv != []:
context.updateGridVariable('Your_Grid_Var_Name', gv)
I hope this helps!