Announcement

Collapse
No announcement yet.

How propose a new value for some fields every new entry

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How propose a new value for some fields every new entry

    Hi,
    I developed a form in which some values are proposed by default based on last value inserted + 1 . For istance last value inserted 10/2019 , new proposed value 11/2019
    It seems easy ... and I did some code that works in onApplicationInit :

    sc_apl_conf("form_ticket", "start", "new");
    $sql_next_rec="SELECT CONCAT(IFNULL(MAX(SUBSTRING_INDEX(`id_ticket`, '/', 1)), 0) + 1 ,'/', YEAR(CURDATE())) FROM ticket ";
    sc_lookup(rs, $sql_next_rec);
    if (isset({rs[0][0]})) // Row found
    {
    [glo_next_id] = ({rs[0][0]}) ;
    {id_ticket}= [glo_next_id];
    $num_prog = explode('/',{id_ticket});
    [glo_index_ticket] = $num_prog[0];
    {ticketid} = [glo_index_ticket];

    }

    When I run the application the first time everything works as expected . Es 10/2019
    The issue is when I click on Insert button and SC save the record. Then using sc_apl_conf("form_ticket", "start", "new"); I was expecting that new record proposed has had the right value
    but it don't work . It has still the previous value Es 10/2019 instead of 11/2019.

    I did try also to copy the same code above into onScriptInit but nothing change. I also tryed to insert a sc_redir (sameform) in onAfterInsert but no way again....
    I'm here stucked...
    Can someone help me ?
    Thanks

  • #2
    Hi,
    maybe I do not completely understand your request, but:

    If I want to set a value in a field for a new record, I usually set it within the onBeforeInsert event.

    This is independent from the status of the form and will be executed for inserts only.

    Hope this can help you!

    Sincerely

    Gunter Eibl
    Gunter Eibl
    email@GunterEibl.de

    asdw.de - Scriptcase & Open Source projects (German/English)
    scriptcase.coach - professional coaching for Scriptcase users (German)
    GunterEibl.de - About me (German)

    Comment


    • #3
      Hello Gunther,
      thanks for reply.
      The application works nicely only the first time when I run it . Then , if I insert a new record clicking on add button , the application propose again the same id/year not the right next one as expected.
      Have a look to video
       

      Comment


      • #4
        Hi Giovanni

        You must insert this in OnLoad

        if ( sc_btn_new ) {

        your settings...

        }
        Giorgio Bravi
        Dolphin Software & Thinkware
        giorgio.bravi@dolphin.it

        Comment


        • #5
          WOWWWWWWWWWWWWWWWWWW Giorgio !!!! Number 0ne !!! It works like a charm .... Thanks so much Giovanni

          Comment

          Working...
          X