question

Anggoro P avatar image
0 Likes"
Anggoro P asked Matthew Gillespie edited

Deleting row and sorting based on column value in global table

Hi,

I need to delete some rows that have column value <= 0 and then sort ascending the remaining rows. I am using custom code on reset trigger. My code is as follows, but it doesn't seem to work. I think j parameter on deletetablerow means number of rows that will be deleted.

Anyone has an idea?

int j;
int k;
for (k = 1; k <= 28; k +=1);
{
    int delRow = 0;
    for (j = 1; j < 29; j += 1)
    {
        if (Table("ScheduledPicking_CO")[j]["PickingTime"]<=0)
        {
            delRow = 1;
            break;
        } 
    }
    if (delRow = 1);
    {
        deletetablerow("ScheduledPicking_CO",j);
    } 
}




Choose One
flexscriptcode
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Anggoro P avatar image Anggoro P commented ·
0 Likes 0 ·

1 Answer

·
Raja Sekaran avatar image
1 Like"
Raja Sekaran answered Matthew Gillespie edited

Hi @Anggoro P

I attached the sample model. deleterow-support-1.fsm

Use the below code to update the global table the way you wanted. I hope this helps you.

Table table = Table("GlobalTable1");
for (int j = 1; j <= table.numRows; j++)
{
    if (table[j][1] <= 0)
    {
        table.deleteRow(j);
        j--; 
    } 
}
table.sort(1);

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Anggoro P avatar image Anggoro P commented ·

Hi @Raja Sekaran

Yes it works. Thanks!

However. I got another problem regarding the next reset. Because the content of current table that I resized and sorted is from another table that always has 28 rows, I can't do reset again after delete rows.

Update: I think I change the strategy. Please don't answer this question. Thanks

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.