WilliamEvans1
7 years agoQrew Cadet
Javascript help to duplicate and modify entry N number of times
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):
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)))))