Forum Discussion

AndrewFry's avatar
AndrewFry
Qrew Assistant Captain
6 years ago

Re: Button in Embedded Report

Eric,

Thanks for the response. I am still new to quickbase, so trying to learn as much as I can. Any response helps.
So I think my solution is a few parts, and I want to be able to combine them all into one button, if possible.
I believe I have some of it, but am still struggling with the other parts.

Currently the user opens a new Work Order fills in any needed data, clicks the "Add Job" button, the Work Order record is saved and the user is taken to the Job form. On the job form, the user inputs information for the job, and then in the assignments editable embedded report, enters additional information. They click the Save & Close button, the Job and related assignments are saved, and the user is taken back to the parent work order in edit mode to continue if needed. That process flow is smooth and what I would like to maintain, if possible, or at least as close to that as is possible.

Issue:
I need to bring down a related client from the parent record (Work Orders) to the child record (Jobs). That related client also has to be brought down to the grandchild record (Assignments). All this is to allow a Contacts list in the grandchild record to be conditional based upon the related client, and show only the related contacts to that related client. The grandchild is an editable embedded report  in the child form. The Child and Grandchild being Parent and Child.

In order to have the related client flow down from the child to the grandchild, the child record has to be generated/saved first. Then for the related client to populate in the grandchild record so that the conditional contacts list functions, the grandchild record also has to be generated/saved first too.

It breaks the process flow to require a user to enter some data, save, go back and edit, enter some more data, save, go back and edit, and then save again.

Solution:
I think that I have a solution, but I am only part way there.

My Jobs form didn't incorporate the default "Add Assignment" button because the embedded report is editable.
However, I think that I will add it and edit the code in it.

When clicked, I need it to do the following:

  • Generate/Save the Job form
    • This will allow the related client to be brought down to the Job, and in turn eventually to the assignment
  • Generate/save a new assignment related to the Job
    • This will allow the related client to be brought down to the assignment, and in turn allow the conditional contacts list to function properly.
  • Take me back to the Job form in edit mode so that I can continue making any changes as needed.

One caveat is that in doing this, I need to ensure that I maintain the return path back to the Parent (Work Order) record, so that when I click on Save & Close in the Job form, it saves and then takes me back to the work order in edit mode.

The code I have thus far is the following:

URLRoot() & "db/" & [_DBID_ASSIGNMENTS] & "?act=API_AddRecord"
& "&_fid_6=" & URLEncode ([Job ID#])
& "&rdr=" & Dbid()& URLEncode("?a=er&rid="&[Job ID#])

This is in the Job form, generates a new Assignment and keeps me in the Job form in edit mode.

What it is lacking is saving the Job first (then doing the above), as well as maintaining the return path to the Parent record in edit mode.

I am currently reading through the API guide to get a better understanding of the calls and syntax, as well as messing around with the "URL Formula Buttons for Dummies" app by Mark Shnier, and also wrapping my head around the "Magic Buttons - Having Fun with Formula URLs" app by Kirk Trachy.

If you have any suggestions, thoughts, input, ideas, etc., it is very welcomed!!

P.S. I will have to check out those Empower sessions you recommended.

Too much to absorb, not enough time!! hahaha lol

------------------------------
Andrew
andrew.fry25@gmail.com
------------------------------

3 Replies

  • EvanWestbrook's avatar
    EvanWestbrook
    Qrew Cadet
    Andrew,

    It sounds like your tables look something like the following. Please let us know if that is not correct.


    There are a couple of ways to approach a solution from here:
    1. Code button as described
    2. Think up another way to do it

    Based on the situation you describe, you might want to check out option Number 2 with a QuickBase Automation
    Option 2: QuickBase Automation
    Automations can fire off of a "trigger" field. For your situation, you might do something like:
    1. Create a field on the "grandparent" table, "Work Order," called [Create Trigger]
    2. Make your "Edit Record" button change the "Work Order" record on which it was clicked to "true"
    3. Automation fires when record on "Work Order" changes and [Create Trigger] = "true"
    4. Automation makes child record on "Jobs" and grandchild record on "Assignment" passing down the Record ID# of the records created
    5. Automation changes [Create Trigger] = "false"

    Option 1: Code button
    Keeping in mind this seems a little complicated for the situation you describe and embedded JavaScript is not officially supported by QuickBase, you could do something like the following:

    // Define API Call for Adding Record
    var text url = URLRoot() & "db/" & [_DBID_WORK_ORDER] & "?act=API_AddRecord" & "&_fid_6=" & URLEncode ([Job ID#]));// Define a Callback to run when API call completes
    var text callback = "function(xml){destrid=$(xml).find('rid').text();newpage='" & URLRoot() & "db/" & [_DBID_JOB] & "?a=dr&rid='+destrid;window.location.href=newpage";
    
    // Define Script to execute when button is clicked
    var text script = "javascript:$.get('" & $url & "'," & $callback  & "});void(0)";
    
    $script;


    The code above executes an API call, parses the the data QuickBase returns on success, extracts a value, and redirects a user to the a different page. In theory, you could make a callback that creates the child and grandchild record. This method has been hit and miss with me.











    ------------------------------
    Evan Westbrook
    PRIME Developer
    Harder Mechanical Contractors Inc.
    Portland OR
    ------------------------------
    • AndrewFry's avatar
      AndrewFry
      Qrew Assistant Captain
      Evan,

      Thanks for the very detailed response. I very much appreciate it. Sorry for the delayed follow-up on my end. I have been on vacation for the past few days.

      Yes, that is how I have the tables set up.

      I understand how your Option #2 works, in theory. However, for it to work as you suggest, wouldn't the Work Order Record ID would first need to be generated? Meaning the work order would need to be saved so that it had an associated Record ID# first, before the automation can run, right?

      With how the process flow works currently, generating the Work Order first, then manually going back in to edit it​ to click a button breaks the flow somewhat.

      Also, if we set it up to generate a new child and grandchild record each time it was edited, we would have more children records than really are needed. The Grandparent record will be edited multiple times throughout the process, so we don't want to generate a child/grandchild record each time.

      However, after reading through your suggestion, I had a thought, but am not sure if it will work.

      Ideally, from within the work order form, if I click on "Add new Job", the code in the button would save the Work Order (thus generating a Record ID#), and then also generate a new job record, taking me back to the Work Order form in edit mode.
      By doing it this way, I wouldn't need to worry about saving the return pat back to the Work Order from the Jobs form.

      I have the code to save and keep working. It is currently in a Formula Rich Text button:

      "<div class='Vibrant Success' onclick=$('#footerSaveAndKeepWorkingMenuOption').click();>Save and Keep Working</div>"​

      I also have the code to generate a new Job, take me back to the Work Order in edit mode. It is currently in a Formula URL button:
      URLRoot() & "db/" & [_DBID_JOBS] & "?act=API_AddRecord"
      & "&_fid_16=" & URLEncode ([Work Order ID#])
      & "&rdr=" & Dbid()& URLEncode("?a=er&rid="&[Work Order ID#])​​

      I was hoping to combine them both into a single button, so that it first runs the "Save & Keep working" and then generates the Job.

      I tried the following:

      "<div class='Vibrant Success' onclick=$('#footerSaveAndKeepWorkingMenuOption').click();>Save and Keep Working</div>"
      & URLRoot() & "db/" & [_DBID_JOBS] & "?act=API_AddRecord"
      & "&_fid_16=" & URLEncode ([Work Order ID#])
      & "&rdr=" & Dbid()& URLEncode("?a=er&rid="&[Work Order ID#])​​

      However, when I went to combine them, I get an error message. I am sure it is due to my lack of experience in syntax and combining different coding types.

      Any thoughts? Do you think something similar to the above would work? I am trying to make it as simple as possible.

      ------------------------------
      Andrew
      andrew.fry25@gmail.com
      ------------------------------
      • EvanWestbrook's avatar
        EvanWestbrook
        Qrew Cadet
        Andrew,

        Thanks for clarifying your use case!

        A revised version of Option 2 might work:
        You can set up Automations to fire on different conditions including "only add records" and "add or modify records". Additionally, any automation will fire after the record is created, so you won't have to worry about [Record ID#] not yet existing. With that in mind, maybe you could do something like the following:
        1. Automation 1
          1. When "Work Order" Record is added, then "do stuff." No need for a button there unless you have use cases where child records are not needed.
        2. Automation 2
          1. When "Work Order" Record is added or modified and conditions are met, then "do stuff."
        This way you can only add child records on set up and only do updates on other conditions if needed.

        Regarding the button:
        Without getting too into the weeds, the code in your last message generates an error due to syntax. Formula Rich Text fields allow you to inject HTML code into native QuickBase, but you have to write all of the code. In Formula URL buttons, QuickBase wraps a URL link in HTML code for you. That's why URL based API Calls work in Formula URLs, but you have to wrap additional code around the URL based API call for it to work in Rich Text.

        What you describe can be done, but it's a little advanced. If you want to go down that route, I would recommend researching how to embed JavaScript scripts in HTML code using jQuery (that's what the "$" indicates) and using callback functions in jQuery's "onClick()" function.

        ------------------------------
        Evan Westbrook
        PRIME Developer
        Harder Mechanical Contractors Inc.
        Portland OR
        ------------------------------