How to remove an instance of flex repeater on button click?

I have a file upload component which when uploads image file save it to database and flex repeater is used to retrieve the uploaded image file from the database and display it, how can I write a script for deleting the particular image from database when I press the delete button in the flex repeater.

Thank You.

In the query which populates your Flex Repeater, make sure you’re bringing along the id column value for each image, and supply this id as a param value.
In the View which contains the button, make sure you’re using this id value to execute an update query along the lines of

query = 'DELETE FROM photo_table WHERE id={0};'.format(
system.db.runUpdateQuery(query=query, database=<database>)

This will only remove the row from the table.

If you then want to refresh the binding of your Flex Repeater, you could use system.perspective.sendMessage() (documentation), coupled with a message handler on the Flex Repeater.

1 Like

I tried as you told still i am missing something:

Flex repeater instances with id in it:

id param in view where button is present:

button onClick event:

on clicking row is not deleting from database

Are you getting any error in your Gateway logs?

Do you have a default database specified for the project? I see that you removed the database argument form the script call.

Do you actually have a column named “id” as part of the images2 table?

It looks like you’re correctly applying the id from your query, but I don’t see the query which populates the Flex Repeater so I can’t verify that…

It’s possible that the query I supplied you isn’t working - I didn’t actually test the query because I don’t have all of the pieces set up as you do. You could try supplying the image_as_bytes string since you have it and specify that column of the table instead…

Actually problem is with getting which instances of flex repeater got clicked I tried by changing the delete script for deleting all and its working
this code deletes all images in database but I am not able to pass the particular id to the sql statement for deleting that row.

Don’t attempt to figure out which instance was clicked. The id param should correlate to the row in the database:

    id      |        image_as_bytes
    1       |        cuabIUcbAOPUcbIOAUbojAUB......
    2       |        uviBSEIVUbegovubSOEubOieu......
    3       |        sevouBEvouBWeovuBKEFHAUB......
    4       |        voUWBEovubWEoviunWHAUB......
    5       |        eOUvbweouvbWOUvbJAUB......

So you should populate your Flex Repeater’s instances with a query like

select id, image from images2;

Flex Repeater’s instances

i tried printing the id in a label in view and it shows correctly

SQL doesn’t have direct access to perspective properties and objects. You must parameterize the query and pass the properties to the query parameters.

@pturmel: That’s what we’re doing.
@ptchanchal: if you are able to send me the view.json files for your two Views, I’ll attempt to replicate the problem when I have some time later in the day.

Ah, brain-freeze. Thought I was looking at the Update query that deletes based on id.

ya i will send that in between I noticed that its due to data type concatenation issue



if write a query like:
query = “DELETE FROM images2 where id = 27”
it works

And also tried to print the value of id in other label and its giving correct value as required but its not able pass it to sql

the below statement return correct id according to the button clicked but i couldn’t pass it to sql
self.getSibling(“Label_0”).props.text= self.getSibling(“Label”).props.text

Try printing the query before you actually execute it, so that we can see what’s being sent.


To fix the TypeError, just wrap the args variable as a str:

query = "DELETE from images2 where id=" + str(arg)

The Label is working because we wrap everything in Strings behind the scenes.

1 Like

Remember when I asked if there were any errors in the logs?

This should have generated an error:

query = 'DELETE FROM photo_table WHERE id={0};'.format({})


query = 'DELETE FROM photo_table WHERE id={0};'.format(

Wow! thank you so much it worked, Now refreshing flex repeater is only left