How do I ask user "Add more data?" after insert?

I am building a shipping tracking application using SC5. I have a form “createshipment” where the user enters most of the data, but only up to 5 lines of item detail.

I want to be able to ask the user “Enter more items before creating bill?” then redirect them based on “Yes” or “No” answer.

Example:

  1. User enters FROM/TO information, and 5 lines of packages detail (pieces,weight,L,W,H)
  2. After submitting form (insert data) the user should see “Add more items?”
  3. If user clicks “Yes”, then new form loads (shipmentdetail) to enter unlimited lines of packages (pieces,weight,L,W,H)

I did figure out how to (a) insert the data in ‘createshipment’, then (b) load the ‘shipmentdetail’ form with
SELECT id FROM shipment WHERE userid = [s_userid] ORDER BY id DESC LIMIT 1
(That will only load the last shipment id for the current logged in user)

Anyone know how to achieve this extra “Yes”/“No” form in-between the 2 other forms??

Re: How do I ask user “Add more data?” after insert?

Have a look at sc_confirm and sc_redir()

Regards,
Scott.

Re: How do I ask user “Add more data?” after insert?

I couldn’t get sc_confirm() to work because it doesn’t give a return value for “No” (or False, or Null).

What I ended up doing: (2 different methods worked)

Method 1:
In Form1 create a custom Select box or Radio options to pass whatever value you desire to form 2 (like “Add more on next page?” with options “Yes (1), No (0)”)
In Form2 during onInit or OnLoad do a check for incoming variable, use sc_redir() based on value
if 1 then sc_redir(editable_grid) else continue Form2

Seems like endless possibilities this way, but I didn’t want a select box or other “easy to miss” options on the screen, I wanted a yes/no prompt to the user.

Method 2: (What I went with)

Form1 uses Table1 with all main one-time entry fields (name, address, phone, To, From, Notes, etc.) , Toolbar only allows “Insert”, exit page = Container1

Container1 = Form2 on Left, Form3 on Right

Form2 = Single Record edit form to make any necessary update to data entered in form1, onLoad uses sc_lookup(data,“select id from parent_table where userid = current_user order by id DESC LIMIT 1”); – form has no exit (returns to itself), Toolbar uses “Update” only.

Form3 = Editable Grid with “line items”
Table2 with fields like (id,Table1_parent_id, pcs, weight, L,W,H,)
Toolbar uses “Insert” only, 20 inclusion rows with hidden field “parent_id” using same sc_lookup as above for value of parent_id
onAfterInsertAll = sc_redir(main_menu) with target “_top” (or use sc_redir(Form1) with target “_parent” )

Re: How do I ask user “Add more data?” after insert?

Can someone explain the point of sc_confirm()? How is it supposed to be used?

NB: The “help” file certainly doesn’t explain it too well…

Re: How do I ask user “Add more data?” after insert?

the macro sc_confirm is used in PHP buttons.
There are others macros used as messages, like sc_ajax_message and sc_alert.

Re: How do I ask user “Add more data?” after insert?

I forgot that these macros do not return anything. You may have to create a message in Javascript and call it as a function.

Remember that you are not bound to only using what SC provides. You are allowed to create any JS/PHP function you need and call it yourself just as if you are creating your app from scratch.

Regards,
Scott.

Re: How do I ask user “Add more data?” after insert?

Max,
I note that with sc_alert, the following code will work:

if (somecondition)
{
// some code

// code finish
}
sc_alert(“Finished!”);

works.
However,

if (somecondition)
{
// some code

// code finish
sc_alert(“Finished!”);
}

will not work. sc_alert never displays when inside of a conditional block. Is that the intended behaviour?

Thanks

Re: How do I ask user “Add more data?” after insert?

I believe this has due with the fact that you are mixing PHP call(somecondition) and JS (sc_alert).
You are executing server code and then expecting the client to display a message based on the result of the server function.

You would have to have a ‘callback’ for this to work, which SC does not support


      Ext.Ajax.request({
        method: 'POST',
        url: 'php_file/myfunction/',
        params : {
          id_employee: grid_record.get('id_employee')
        },
        success: function(xhr) {
          var jsonResponse = Ext.decode(xhr.responseText);
          if (jsonResponse.success == true) {
            alert('Payroll entry has been created for selected employee!');
          } else {
            alert('Notice: Unable to create payroll entry, possible duplicate entry!');
          }
        },
        failure: function() {
          alert('ERROR: Unable to create employee, please contact support');
        }

php:


myfunction(){ 

 if (somecondition){
   echo '{ success: true }'; 
 } else {
   echo '{ success: false }';
 }

}

Regards,
Scott

Re: How do I ask user “Add more data?” after insert?

Doh! You’re right as always… I’ll use the excuse that it was the end of a long day when I posted that.

Cheers

Re: How do I ask user “Add more data?” after insert?

I still don’t see how I would use this effectively. If you mean that I could use something like this in a button’s code

sc_confirm(“Do it now?”);
// some code here

Irrespective of whether I click OK or CANCEL the code is never executed. The only difference I see is that the screen blanks to a tiny “OK” button. Essentially, as per Scott’s response, a user defined “callback” is probably more useful

But an example of how I would use sc_confirm in a meaningful way would be good, Max, if only to clear the fog from my brain <g>

Cheers

Re: How do I ask user “Add more data?” after insert?

the sc_confirm() only seems to be helpful if you create a PHP function and you want to prompt the user to stop and return to a previous app.

There should be a new type.

Regards,
Scott.

Re: How do I ask user “Add more data?” after insert?

I can’t even see a simple way to effect that, which is why I’ve asked for an example. As best I can tell, PHP code execution stops immediately after a call to sc_confirm, irrespective of OK or Cancel being clicked.

Anyway, no big deal. As you pointed out it’s easy enough to code a solution.

Cheers

Hi All You can use sc_confirm as follows

sc_confirm(“Do you want to add more ?”)
{
… code here
}