Page 1 of 1

Process records in a row

Posted: Thu Feb 01, 2018 5:17 am
by toms
Hi,

I would like to edit records one after the other without going back to the browse form every time.

The workflow should work like this:

1. Fetch the next record (from a table, where a done_flag is not set. e.g. SELECT * FROM customers WHERE cust_done_done is null LIMIT 1;
2. The user inputs data in the edit form/updates some fields
3. The user saves the record (a js/php script would set a 'done' flag/datetime stamp. I know how to do that. Eg. Set cust_done_done = 1 or set it to now())
4. A next record is fetched (basically the same as in step 1)
5. The record is opened in the edit form

Now I'm not sure if there is an inbuilt way to open "any" next record that meets a criteria ( cust_done_done is null)

Looking at nuForm(), I can only pass a specific row id or open the browse form

Code: Select all

nuForm(nuGetProperty('form_id'), r, '', '', '0', '1');
Any advice would be greatly appreciated,
next_record.png

Re: Process records in a row

Posted: Thu Feb 01, 2018 6:44 am
by admin
toms,

I have changed nuReturnNewRecord() to optionally take a primary key as a parameter.

So you'll need the latest from Github.

http://wiki.nubuilder.net/nubuilderfort ... nNewRecord

That way you can return to any record you wish.

(in the example below, it will bring up payments that are due and not paid - if you set a record to Paid and save, it will return the next Outstanding payment that is due)


So in After Save it would look like this...

Code: Select all


$today  = Date('Y-m-d');
$s      = "
            SELECT payment_id 
            FROM `payment` WHERE pay_due <= '$today' AND pay_paid = 'Outstanding'
            ORDER BY pay_due
        ";

$t      = nuRunQuery($s);
$r      = db_fetch_row($t)[0];

if(db_num_rows($t)== 0){           //-- new record if no criteria met.
   nuReturnNewRecord();
}else{
   nuReturnNewRecord($r);
}


next_primary_key.PNG
Hopefully, I have understood your question.


Steven

Re: Process records in a row

Posted: Thu Feb 01, 2018 9:03 am
by toms
Steven,

Nice, it works just as I expected! Thanks a lot for the quick implementation!

Re: Process records in a row

Posted: Thu Feb 01, 2018 9:53 am
by admin
.