Forum Discussion

jrossausiscom's avatar
jrossausiscom
Qrew Assistant Captain
5 years ago

Copying the Children of a Parent only (Code Assistance needed)

Currently working on a new app for our company in which I am changing some items and reusing or rebuilding others.

I ran into an issue with a URL button.  What I need it to do is copy the related children of a parent (but NOT the parent) then related said new copies to the work request the user is in.  Basically the chosen type is holds the "templates" and the copies will become the "live" records.

At a high level, this is what I need.
  • Children of the Related Staging Type are copied
  • The fresh copies are related to the Request and Job.
  • The fresh copies have their template checkbox deselected and the service date put in.  This filters them from the original templates.
  • Once done, the script should return the user to the request so they can check the data.

Here is what I have so far based on the old code from the old app.  Note that I replaced the table ID's with simple names just for the ease of this discussion, the actual code has the real values.  Lastly, note that the "Transactions" items have been commented out as I do not know if I will need them, so i am keeping them commented for now.

When I run this code, I just get a "page cannot be found" error.  Any ideas?  This code is almost identical to the old one except that the old one has one less set of actions and no comments...

//Java Magic? (Copies the Children, does NOT copy parent [hopefully])
    "javascript:void(window.open('" & URLRoot() & "db/" & Dbid() & "?a=dbpage&dbid=" & "Parent Table"
        & "&pagename=copyParentChild-Select.html&onlyDBIDs=FINACIALS.COSTS.CONFIGS.TRANSACTIONS&rid=" & URLEncode([Related Project Staging Type])


//Related the Children to the Staging Request
    & "& dest=refresh&destrid=null & FINACIAL-43=" & URLEncode([Staging ID]) //Relates Financials to the Staging Request
    & "& COSTS-49=" & URLEncode([Staging ID]) //Relates Costs to the Staging Request
    & "& CONFIGS-31=" & URLEncode([Staging ID]) //Relates Configs to the Staging Request
//    & "& TRANSACTIONS-24=" & URLEncode([Staging ID]) //Relates Transactions to the Staging Request

//Relates the Children to the Job
    & "& FINACIALS-44=" & URLEncode([Related Job])  //Relates Financials to the Job
    & "& COSTS-34=" & URLEncode([Related Job])  //Relates Costs to the Job
    & "& CONFIGS-32=" & URLEncode([Related Job])  //Relates Configs to the Job
//    & "& TRANSACTIONS-17=" & URLEncode([Related Job])  //Relates Transactions to the Job

//Encodes Today's Date, and Unchecks Template
    & "& FINACIALS-34=" & URLEncode(Today())  //Relates Financials to the Job
    & "& FINACIALS-33=" & URLEncode(false)  //Unchecks Template in the Financials
    
    & "& COSTS-35=" & URLEncode(Today())  //Relates Costs to the Job
    & "& COSTS-31=" & URLEncode(false)  //Unchecks Template in the Costs
    
    & "& CONFIGS-33=" & URLEncode(Today())  //Relates Configs to the Job
    & "& CONFIGS-34=" & URLEncode(false)  //Unchecks Template in the Configs
    
//    & "& TRANSACTIONS-17=" & URLEncode(Today())  //Relates Transactions to the Job
//    & "& TRANSACTIONS-17=" & URLEncode(0)  //Unchecks Template in the Transactions

//Creates the window?
    & "','copyRecursive','top=240,left=320,width=400,height=150,location=no,menubar=no,toolbar=no'))"​


------------------------------
John Ross
------------------------------
  • The best approach is to scrap that code page.

    There is an API for CopyMasterDetail.  https://help.quickbase.com/api-guide/understandreference.html

    The User would select a Template Project which holds the correct child tasks and import them into the current record that the user is on.  There is no need to use a code page.

    It's a simple URL formula field.  Give it a try and post back if you get stuck or contact me for some quick consulting help of about an hour.

    The final formula will look something like this

    var text Import = URLRoot() & "db/" & Dbid() & "?act=API_CopyMasterDetail"
    & "&relfids=65" // relationship report link field to the correct child table
    & "&destRID=" & [Record ID# of Template Project] // source of he children
    & "&sourcerid=" & [Record ID#];  // destination of he copied children is the record we are sitting on.

    var text DisplayProject = URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID# of Template Project];


    $Import
    & "&rdr=" & URLEncode($DisplayProject);




    ------------------------------
    Mark Shnier (YQC)
    Quick Base Solution Provider
    Your Quick Base Coach
    http://QuickBaseCoach.com
    mark.shnier@gmail.com
    ------------------------------
    • jrossausiscom's avatar
      jrossausiscom
      Qrew Assistant Captain
      Hello

      Thank you for this example code, I am looking at it now.  To be clear, when it asks for the relationship report link field ID, what do I do if I have multiple children?  In this case 4  (Well, 3 and maybe the 4th later).

      Also, does this still allow me to write specific data to each child?

      ------------------------------
      John Ross
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        The relationship report link fields for the different types of child records would be listed comma separated.

        "&relfids=65,66,67"

        The template records will be just copied in from the Template children.  You cannot auto write to them.  What do you need to write to them.  Can you just have a lookup fields from the parent down to the children?

        ------------------------------
        Mark Shnier (YQC)
        Quick Base Solution Provider
        Your Quick Base Coach
        http://QuickBaseCoach.com
        mark.shnier@gmail.com
        ------------------------------