Mass update record using run button

Hi,

​I have created a grid and there is a run button. Basically, I need to tick on the checkbox for the records I wanted and when clicked on the run button, a field will auto update.

In the grid > event > onScriptInit:
[i] = 0;
[total_chked] = array();

In the button > onRecord: $arr=[i];
[arr_vl][$arr]={id};
[i]++;
$invoice=‘INV001’;

sc_exec_sql(“UPDATE purchase SET invoice=’$invoice’ WHERE id = ‘{id}’”);

​In the button > onFinish:
[tot] = [arr_vl];

​The above code I hardcorded the invoice number but I need that when the user tick on the checkbox for the records and click run button, there is a prompt for them to enter the invoice number.

Can anyone kindly advise? Thanks.

There are several solutions for this problem, but in fact all are more-or-less a work-around. The reason for this is that a grid cannot have regular fields for input as that would require a form. One option might be to turn the process around. Start asking for an invoice number and after ok, show the grid. You can pass the invoice number as a global. This is imho the most easy solution. Other option might be injecting a bunch of javascript. I try to avoid :wink: Final option is to create a unique id and do it your way, but after processing you jump to a form to enter the real id. Then a sql update would replace the old id by your new one (or delete the old ones if cancel). Well, just a few ideas, hope these are helpful.

Sorry to revive an old post, but I stumbled upon this question while searching for a solution to this myself.
Albert’s first idea triggered what ended in the solution for me. It’s not elegant, and it will probably break with some future SC update.

I have a grid, where I want to mass modify selected records with a variable value (not a fixed one)… just to clarify my example, think of it as several discount values (10%,20%,30%,40%)

Instead of using a form, and global variables, I set up the grid with SEARCH as the initial module.

Then, I added a New field in Fields (inside SEARCH submenu, not in the grid itself (ie: {discount})
.
This new field is a SELECT, where I have all the values I would like to be selected.(10%,20%,30%,40%)

Next, I added a RUN button (ie: ‘Apply Discounts’). Mind you that here is the “not elegant” part of my solution… Run buttons should not work on grids with search as an initial module, but in reality, they do work fine. you will see an alert about this.

Now, on the OnRecord event of the RUN button, i use the field set up inside the search to modify each record (here is another thing… the field has to be called as a global variable, using square brackets … ie [discount]

At least in my case, with scriptcase 9.4, works like a charm.