Discussions

 View Only
  • 1.  Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-08-2021 15:03
    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
    ------------------------------


  • 2.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-08-2021 15:16
    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
    ------------------------------



  • 3.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-08-2021 16:10
    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
    ------------------------------



  • 4.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-08-2021 16:14
    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
    ------------------------------



  • 5.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-15-2021 17:06
    Mark

    Sorry for the delay.

    Basically we have a template that let's you choose the type of work we will do.  This is the staging type.  Each staging type has 3 types of children, a Cost, Financial, and Config.  Note that there can be multiple of each of those 3.  How our old system is setup and running currently, we have a button that makes fresh copy of the related (related by the Staging Type) Costs, Financials, and Configs.  Those fresh copies are then related to the request and job and unrelated to the Staging Type.

    Basically the goal was for the Staging Type to only ever show it's "template" children, and for each request and job to have their own "live" costs, financials, and configs that are only related to said request and job.

    ------------------------------
    John Ross
    ------------------------------



  • 6.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-15-2021 17:58
    ... I see you last comment, but was there a question in there?  Did you try what I suggested?

    But I see that I had he source and destination reversed.

    var text Import = URLRoot() & "db/" & Dbid() & "?act=API_CopyMasterDetail"
    & "&relfids=65" // relationship report link field to the correct child table
    & "&destRID=" & [Record ID#] // source of he children
    & "&sourcerid=" & Record ID# of Template Project];  // 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
    ------------------------------



  • 7.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-25-2021 15:45
    Hey again Mark

    The children need to have the request and job record ID's to them to related them to said request and jobs.

    ------------------------------
    John Ross
    ------------------------------



  • 8.  RE: Copying the Children of a Parent only (Code Assistance needed)

    Posted 01-25-2021 17:02
    I think this would take some one on one assistance to be able to see the app to fully understand what that old code was doing and what functionality do you want now or what functionality you're trying to replicate.   If you have a small budget, feel free to contact me at the email address below for one on one assistance.  

    I typically do not charge for a short call if I determine on the call that I cannot help you.

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