AddRecord API with conditions

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered

I've got several formula URL buttons (25 buttons total) on a Master form that currently add a record to a child table and set certain fields on these new child records.  The intent was that I would hide the non-applicable buttons using dynamic form rules, however, I've run in to an issue with too many derived fields on the form.

I am now trying to combine these buttons in to only a few buttons, but in order to do this I will still need to be able to set the certain fields based on the Project Description field from the master record.  Is it possible to combine an IF statement with the AddRecord/EditRecord API functionality to accomplish this? 

Photo of Jennifer

Jennifer

  • 10 Points

Posted 4 years ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,780 Points 50k badge 2x thumb
Yes, this is very easy to do. Why don't you post an example of one of your buttons and a description of one of the conditions that your dynamic form rules would have done and I can help you reformat your button to act flexibly depending on the data in the record.
Photo of Jennifer

Jennifer

  • 10 Points
Thanks!  I figured it couldn't be too hard!  Here is an example... I marked the conditional parts with an **...

var text EditRecord =
URLRoot() & "db/" & [_DBID_QUOTES]  
& "?act=API_EditRecord&rid="
& [Project ID#] & "&_fid_73=Project Submitted - In Progress";

var text AddTaskONE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
**& "&_fid_6=Statement Set Up or Statement Reformat" //setting Task Description field
       **IF <Project Description> (fid=152 ) = “Statement Set Up”, “Statement Set Up”,
       **IF <Project Description> (fid=152 ) = “Statement Reformat”, “Statement Reformat”,
& "&_fid_135=Artwork Set Up"; //setting Task Type field

var text AddTaskTWO =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
**& "&_fid_6=Statement Set Up or Statement Reformat" //setting Task Description field
       **IF <Project Description> (fid=152 ) = “Statement Set Up”, “Statement Set Up”,
       **IF <Project Description> (fid=152 ) = “Statement Reformat”, “Statement Reformat”,
**& "&_fid_135=Data Set Up"; //setting Task Type field

var text AddTaskTHREE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
**& "&_fid_6=Statement Set Up or Statement Reformat" //setting Task Description field
       **IF <Project Description> (fid=152 ) = “Statement Set Up”, “Statement Set Up”,
       **IF <Project Description> (fid=152 ) = “Statement Reformat”, “Statement Reformat”,
& "&_fid_135=Test"; //setting Task Type field

var text AddTaskFOUR =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
**& "&_fid_6=Statement Set Up or Statement Reformat" //setting Task Description field
       **IF <Project Description> (fid=152 ) = “Statement Set Up”, “Statement Set Up”,
       **IF <Project Description> (fid=152 ) = “Statement Reformat”, “Statement Reformat”,
& "&_fid_135=LIVE Sign Off"; //setting Task Type field

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

$EditRecord
& "&rdr=" & URLEncode($AddTaskONE)
& URLEncode("&rdr=" & URLEncode($AddTaskTWO))
& URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskTHREE)))
& URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskFOUR))))
& URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($DisplayParent)))))
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,780 Points 50k badge 2x thumb
I think that you mostly have it figured out.



var text EditRecord =
URLRoot() & "db/" & [_DBID_QUOTES]  
& "?act=API_EditRecord&rid="
& [Project ID#] & "&_fid_73=Project Submitted - In Progress";

var text AddTaskONE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(        //Statement Set Up or Statement Reformat" //setting Task Description field
  &     IF([Project Description]= “Statement Set Up”, “Statement Set Up”,


          [Project Description= “Statement Reformat”, “Statement Reformat”)) // when you are assigning specials characters into a URL, like a space, you should URLEncode to be safe)


& "&_fid_135=Artwork Set Up"; //setting Task Type field

var text AddTaskTWO =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(   //Statement Set Up or Statement Reformat" //setting Task Description field
  &    
IF([Project Description]= “Statement Set Up”, “Statement Set Up”,

          [Project Description= “Statement Reformat”, “Statement Reformat”))

& "&_fid_135=Data Set Up"; //setting Task Type field

var text AddTaskTHREE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(   Statement Set Up or Statement Reformat" //setting Task Description field
      

   &  IF([Project Description]= “Statement Set Up”, “Statement Set Up”,

          [Project Description= “Statement Reformat”, “Statement Reformat”))

& "&_fid_135=Test"; //setting Task Type field

var text AddTaskFOUR =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(   //Statement Set Up or Statement Reformat" //setting Task Description field
 &  IF([Project Description]= “Statement Set Up”, “Statement Set Up”,

          [Project Description= “Statement Reformat”, “Statement Reformat”))

& "&_fid_135=LIVE Sign Off"; //setting Task Type field

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

$EditRecord
& "&rdr=" & URLEncode($AddTaskONE)
& URLEncode("&rdr=" & URLEncode($AddTaskTWO))
& URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskTHREE)))
& URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskFOUR))))
& URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($DisplayParent)))))
Photo of Jennifer

Jennifer

  • 10 Points
Thanks again, Mark!  Of course it was just that easy :)  You are always so helpful!

There were a couple of syntax errors I had to work through, but below is what ended up working:

var text EditRecord =
URLRoot() & "db/" & [_DBID_QUOTES]  
& "?act=API_EditRecord&rid="
& [Project ID#] & "&_fid_73=Project Submitted - In Progress";

var text AddTaskONE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(
  If([Project Description]= "Statement Set Up", "Statement Set Up",
          [Project Description]= "Statement Reformat", "Statement Reformat")) //setting Task Description field
& "&_fid_135=Artwork Set Up"; //setting Task Type field

var text AddTaskTWO =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(
  If([Project Description]= "Statement Set Up", "Statement Set Up",
          [Project Description]= "Statement Reformat", "Statement Reformat")) //setting Task Description field
& "&_fid_135=Data Set Up"; //setting Task Type field

var text AddTaskTHREE =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(
   If([Project Description]= "Statement Set Up", "Statement Set Up",
          [Project Description]= "Statement Reformat", "Statement Reformat")) //setting Task Description field
& "&_fid_135=Test"; //setting Task Type field

var text AddTaskFOUR =
URLRoot() & "db/" & [_DBID_TASKS] //name of the child table
& "?act=API_AddRecord&_fid_142=" & URLEncode ([Project ID#]) // connecting the child to its parent...here [Project ID#] is the key in parent (Quotes/Projects) and _fid_142 is the related parent in the child (Tasks)
& "&_fid_6=" & URLEncode(
 If([Project Description]= "Statement Set Up", "Statement Set Up",
          [Project Description]= "Statement Reformat", "Statement Reformat")) //setting Task Description field
& "&_fid_135=LIVE Sign Off"; //setting Task Type field

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

$EditRecord
& "&rdr=" & URLEncode($AddTaskONE)
& URLEncode("&rdr=" & URLEncode($AddTaskTWO))
& URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskTHREE)))
& URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($AddTaskFOUR))))
& URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($DisplayParent)))))