Forum Discussion

ToddM's avatar
ToddM
Qrew Cadet
23 days ago
Solved

Save and New Button on Legacy form

I'm trying to build what I thought would be a simple button for saving the current child record and adding a new one to the same parent record. I'm essentially just trying to duplicate the native Save & New button so I can place it next to the native Save and Close button. Will I need a code page for this?

I have programs that have many program charges and the Users want separate buttons for adding additional records and saving the record when done adding multiple charges. FID_6 is the related Program RID in the child table, Program Charges. Any thoughts would be appreciated! 

  • I did it with a code page like this:

    Formula on child:

    var text parentValue = ToText([Related Record]); //update to your field
    var text childDb = "abc123xyz"; //update to your child dbid
    var number parentFid = 7; //update to related parent fid for related field above
    
    var text url =
    URLRoot() & "db/" & $childDb &
    "?a=API_GenAddRecordForm" &
    "&_fid_" & ToText($parentFid) & "=" & URLEncode($parentValue) &
    "&NextURL=" &
    URLEncode(
        URLRoot() &
        "db/" & Dbid() &
        "?a=dbpage&pageID=73" & //replace 73 with your code page ID
        "&db=" & $childDb &
        "&fid=" & ToText($parentFid) &
        "&parent=" & URLEncode($parentValue)
    );
    
    "<a class='Vibrant Success SaveBeforeNavigating' href='" & $url & "'>Save and New</a>"

    Create a code page:

    <!DOCTYPE html>
    <html>
    <head>
    <script>
    const p = new URLSearchParams(window.location.search);
    
    const db = p.get("db");
    const fid = p.get("fid");
    const parent = p.get("parent");
    
    window.location =
        location.origin +
        "/db/" + db +
        "?a=API_GenAddRecordForm" +
        "&_fid_" + fid + "=" + encodeURIComponent(parent) +
        "&NextURL=" + encodeURIComponent(window.location.href);
    </script>
    </head>
    <body></body>
    </html>

    Button triggers the save and redirects to code page with context in the URL, and code page redirects back to record using the context.

7 Replies

  • Forgot to show current button:

    var text db = Dbid();

    "<a class='Vibrant Success' href='" &
    URLRoot() & "db/" & $db &
    "?a=er" &
    "&rid=" & [Record ID#] &
    "&z=" & Rurl() &
    "&NextURL=" &
    URLEncode(
        URLRoot() & "db/" & $db &
        "?a=API_GenAddRecordForm" &
        "&_fid_6=" & ToText([Related Program])
    ) &
    "'>Save & Add Another Charge</a>"

    • Denin's avatar
      Denin
      Qrew Captain

      I did it with a code page like this:

      Formula on child:

      var text parentValue = ToText([Related Record]); //update to your field
      var text childDb = "abc123xyz"; //update to your child dbid
      var number parentFid = 7; //update to related parent fid for related field above
      
      var text url =
      URLRoot() & "db/" & $childDb &
      "?a=API_GenAddRecordForm" &
      "&_fid_" & ToText($parentFid) & "=" & URLEncode($parentValue) &
      "&NextURL=" &
      URLEncode(
          URLRoot() &
          "db/" & Dbid() &
          "?a=dbpage&pageID=73" & //replace 73 with your code page ID
          "&db=" & $childDb &
          "&fid=" & ToText($parentFid) &
          "&parent=" & URLEncode($parentValue)
      );
      
      "<a class='Vibrant Success SaveBeforeNavigating' href='" & $url & "'>Save and New</a>"

      Create a code page:

      <!DOCTYPE html>
      <html>
      <head>
      <script>
      const p = new URLSearchParams(window.location.search);
      
      const db = p.get("db");
      const fid = p.get("fid");
      const parent = p.get("parent");
      
      window.location =
          location.origin +
          "/db/" + db +
          "?a=API_GenAddRecordForm" +
          "&_fid_" + fid + "=" + encodeURIComponent(parent) +
          "&NextURL=" + encodeURIComponent(window.location.href);
      </script>
      </head>
      <body></body>
      </html>

      Button triggers the save and redirects to code page with context in the URL, and code page redirects back to record using the context.

      • ToddMolino's avatar
        ToddMolino
        Qrew Cadet

        Hi Denin - I moved this button from the legacy form to the new form and it broke. It worked fine for testing on the legacy form. I'm not sure how to update the URL path. I heard there was a difference between forms. Any clue? 

  • I changed the color of the button and I bet that's what broke it. Fixed and works good.