Discussions

 View Only
  • 1.  Javascript help to duplicate and modify entry N number of times

    Posted 06-06-2018 06:33
    Hi,

    I have a function which duplicates an entry and modifies a field with each duplicate... it works but it's clunky.

    The only field that changes is "month number" (not a date) - i.e. you enter the first item in Month Number = 1, then it duplicates it 11 times setting the month number from 2 to 12...

    This was written without javascript, but quickly the resulting URL was far too long so I had to split it into two different buttons to press...even then it sometimes has issues running if any of the source fields have a lot of data in them.... Also it doesn't refresh the page after it's done.


    I would like some help / suggestions on how to modify this code below so that:

    1. Javascript is used to execute each iteration - so the function can be done with one button and doesn't break if the URL is too long due to large fields...

    2. After the function is complete, the page refreshes.

    Below is my current code - from the first button (loops 6 times to keep url length down):


    //define the fields that are the same in each iteration
    var text COMMMONFIELDS = 
    "&_fid_8=" & [Budget Status Flag]
    & "&_fid_22=" & URLEncode([Comments])
    & "&_fid_25=" & [Account Code]
    & "&_fid_28=" & [Related Company]
    & "&_fid_244=" & [Item Status]
    & "&_fid_72=" & [General Cost Currency]
    & "&_fid_73=" & URLEncode([General Cost Description])
    & "&_fid_122=" & [People Cost Number of Days Required]
    & "&_fid_156=" & URLEncode([Item Vendor])
    & "&_fid_160=" & [Spend Country]
    & "&_fid_9=" & [Recoverable?]
    & "&_fid_165=" & [General Cost Quantity]
    & "&_fid_164=" & [Predefined Daily Cost Quantity]
    & "&_fid_163=" & [Predefined Cost Quantity Completed]
    & "&_fid_114=" & [Related People Cost]
    & "&_fid_81=" & [Predefined Daily Cost Days]
    & "&_fid_71=" & [General Unit Cost]
    & "&_fid_69=" & [Related Predefined Daily Cost]
    & "&_fid_68=" & [Related Predefined Cost]
    & "&_fid_37=" & [Related Fx]
    & "&_fid_32=" & [Item Type]
    & "&_fid_47=" & [Related Sub-Project]
    & "&_fid_241=" & URLEncode([Original Item Project Category])
    & "&_fid_305=" & [Item has been Deferred]
    & "&_fid_302=" & [Select Month For Split]
    & "&_fid_299=" & [People Cost # Days to DEFER]
    & "&_fid_296=" & [Predefined Daily Cost Qty to DEFER]
    & "&_fid_295=" & [Predefined Daily Cost # of Days to DEFER]
    & "&_fid_294=" & [Predefined Daily Cost Days / Qty]
    & "&_fid_292=" & [Predefined Cost Quantity to DEFER]
    & "&_fid_281=" & [General New Split Qty to DEFER]
    & "&_fid_280=" & [General New Split Unit Cost to DEFER]
    & "&_fid_279=" & [General Split Cost / Qty?]
    & "&_fid_259=" & [Item Completion Status]
    & "&apptoken=blahblahmytoken";

    //define the fields that change with each iteration
    var text AddAug = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "8"
    & $COMMMONFIELDS;

    var text AddSep = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "9"
    & $COMMMONFIELDS;

    var text AddOct = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "10"
    & $COMMMONFIELDS;

    var text AddNov = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "11"
    & $COMMMONFIELDS;

    var text AddDec = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "12"
    & $COMMMONFIELDS;

    var text AddJan = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "1"
    & $COMMMONFIELDS;

    var text AddFeb = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "2"
    & $COMMMONFIELDS;

    var text AddMar = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "3"
    & $COMMMONFIELDS;

    var text AddApr = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "4"
    & $COMMMONFIELDS;

    var text AddMay = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "5"
    & $COMMMONFIELDS;

    var text AddJun = URLRoot() & "db/" & [_DBID_NEWITEMS] & "?act=API_AddRecord"
    & "&_fid_43=" & "6"
    & $COMMMONFIELDS;

    //combine it all into a URL button
    $AddAUG
    & "&rdr=" & URLEncode($AddSEP)
    & URLEncode("&rdr=" & URLEncode($AddOCT))
    & URLEncode(URLEncode("&rdr=" & URLEncode($AddNOV)))
    & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($AddDEC))))
    & URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($AddJAN)))))


  • 2.  RE: Javascript help to duplicate and modify entry N number of times

    Posted 06-06-2018 10:31
    There is a non script solution. I will call your Parent Record Projects and the 12 children �Monthly Budgets�

    Make a table called Focus Project.
    Make exactly 1 Record. It will be Record ID of 1.

    Make a relationship where 1 Project has Many Focus Projects.

    Edit the Focus project to choose a Proect and lookup all those common fields into it.

    Make a new table with 12 records in it, called Focus Project Monthly Budgets. Link them to the Focus Project and lookup all the fields and create a formula to calculate the monthly fields.

    Then create a saved table to table copy to copy the 12 monthly budgets into your !onthly Budgets Table.

    Lastly, create a URL formula button on the Project to

    1. Set the Focus Project.
    2. Run the saved import with API_RunImport.
    3. Refresh the Project Record


  • 3.  RE: Javascript help to duplicate and modify entry N number of times

    Posted 06-06-2018 13:19
    Thanks, that's a novel no-script solution! 

    However I had a brain fade when I posted this... I realised that I had posted the question a year ago (sigh) https://community.quickbase.com/quickbase/topics/javascript-to-copy-a-record-n-number-of-times-and-i... and there was a javascript answer in that which I managed to get working, I posted the relpy there.

    Thanks so much for your help!


  • 4.  RE: Javascript help to duplicate and modify entry N number of times

    Posted 06-06-2018 14:25
    Ok, thx for letting me know. So now others seeing this will have a choice of approaches.