Forum Discussion

ChrisSwirtz3's avatar
ChrisSwirtz3
Qrew Member
3 years ago

Button that creates a new record based on the selection in the new record

I have an app with a Companies Table and a Offices Table related by a one Company to many Offices relationship. When a Company wants to create a new Office request, there is a few types of request to choose from (New, Renewal, Relocation), based on which choice is selected, certain info is shown/hidden on the Office record.

Is it possible to create a button on the Company table that when clicked will create a new record in the Office table utilizing the specific type of request the user wants?

For instance, if ABC Company wants to Renew a current office space, they would be able to click on a "Renew" Button and it will create a New Office record where "Renew" is already selected in the Type: dropdown so the correct information is already shown/hidden.

Purpose being to save the user the step of having to click the New Office button and then selecting the type of Request from the dropdown.

------------------------------
Chris Swirtz
------------------------------

8 Replies

  • Can you post (copy/paste)  the code for your current Add Office button, and let me know the field ID# of the field you want to populate. The I will show you the simple change to the code.

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------
    • ChrisSwirtz3's avatar
      ChrisSwirtz3
      Qrew Member
      Hey Mark, here is the code as is.

      URLRoot() & "db/" & [_DBID_SPACES] & "?a=API_GenAddRecordForm&_fid_1115=" & URLEncode ([Record ID#])& "&z=" & Rurl()

      And the field ID that I want to populate is 12

      ------------------------------
      Chris Swirtz
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        np

        URLRoot() & "db/" & [_DBID_SPACES]
        & "?a=API_GenAddRecordForm"
        & "&_fid_1115=" & URLEncode ([Record ID#])
        & "&_fid_12="Renewal"
        & "&z=" & Rurl()

        Just a note about URLEncode

        It never hurts to do URLEncode but when you do it needlessly it just clutters up your formulas and makes them unreadable. In the whole Internet certain characters are not allowed, for example you may have noticed that there are never spaces in a URL. So if for example you wanted to populate "New Lease" into that field, that string has a space in it and would make an illegal URL. So if you were not sure what was going to be put into that field, perhaps it was not a simple hardcoded value but was actually coming from a data field then the syntax would be this 


        URLRoot() & "db/" & [_DBID_SPACES] & "?a=API_GenAddRecordForm"
        & "&_fid_1115=" & URLEncode ([Record ID#])
        & "&_fid_12=" & URLEncode("New Lease")
        & "&z=" & Rurl()
          

        You will also notice how I broke up your formula into separate lines to keep everything in a consistent pattern. It really pays off to keep your formulas stupid simple to read because a month or a week or a year from now you may be the poor soul who needs to figure out what that formula is doing.  Or you may want to be kind to your successor who takes over from you eventually.

        ------------------------------
        Mark Shnier (YQC)
        mark.shnier@gmail.com
        ------------------------------