Forum Discussion

IvanWeiss's avatar
IvanWeiss
Qrew Captain
6 years ago

Multi step API not triggering a new record creation

Hello everyone, relatively new and really getting into the idea of API buttons to automate a lot of things.  The first more complex one I am creating is the deal won button for an opportunity.  When this happens I want to trigger a few things based on the opportunity type (for me design or build).  The first part of this API works fine, deal won stage is changed and the date won is set to Today().  But it is not creating the new task to create the sales order and I cannot figure out why or how to debug this to figure it out.  Any help would be appreciated!

//Button Functionality:
//1.  Change the stage of the opportunity to won
//2.  Set the Date Won to Today
//3.  Check to see if opportunity is of type design.  
//      If true, assign a task to Lisa to create the sales order.
//4.  Redirect back to the same form to display the record with updates.
//*******************************************************************************************************************


//Step 1 and 2
var text urlOne = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
                                    "&rid=" & [Record ID#] &
                                    "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                    "&_fid_9=Won" &
                                    "&_fid_23=" & URLEncode(Today());


//Step 3 - Build urlTwo variable if the type is design.  This assigns the sales order creation to lisa as a task.
var text urlTwoIfDesign = URLRoot() & "db/" & [_DBID_TASKS] & "?a=API_GenAddRecordForm" &
                                "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                "&_fid_31=" & URLEncode(ToUser("ljording@elitestudioe.com")) &
                                "&_fid_36=" &URLEncode("Task created automatically through Opportunity Win Button") &
                                "&_fid_9=" & URLEncode(ToWeekdayN(Today())) &
                                "&_fid_12=" & [Record ID#] &
                                "&_fid_21=" & [Project] &
                                "&_fid_24=Active" &
                                "&_fid_38=" & URLEncode(ToText(ToUserList([Project Solutions T1],[Project Solutions T2]))) &
                                "&_fid_23=Opportunity" &
                                URLEncode("&_fid_83=Not Applicable") &
                                "&_fid_6=Create Sales Order - Design Opportunity";
                                
//Step 3 - Build urlTwo variable if the type is build.  THE FOLLOWING IS A COPY OF THE ABOVE AS I DID NOT BUILD THE LOGIC OUT YET




var text urlTwoIfBuild = URLRoot() & "db/" & [_DBID_TASKS] & "?a=API_AddRecord" &
                                "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                "&_fid_31=" & URLEncode(ToUser("ljording@elitestudioe.com")) &
                                "&_fid_36=" &URLEncode("Task created automatically through Opportunity Win Button") &
                                "&_fid_9=" & URLEncode(ToWeekdayN(Today())) &
                                "&_fid_12=" & [Record ID#] &
                                "&_fid_21=" & [Project] &
                                "&_fid_24=Active" &
                                "&_fid_38=" & URLEncode(ToText(ToUserList([Project Solutions T1],[Project Solutions T2]))) &
                                "&_fid_23=Opportunity" &
                                URLEncode("&_fid_83=Not Applicable") &
                                "&_fid_6=Create Sales Order - Design Opportunity";
                             
//Step 4
var text redirect = URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#];
                                    
//URL Execution
Case(true,
[Opportunity Type] = "Design", $urlOne & URLEncode($urlTwoIfDesign) & "&rdr=" & URLEncode($redirect),
[Opportunity Type] = "Build", $urlOne & URLEncode($urlTwoIfBuild) & "&rdr=" & URLEncode($redirect)
)
  • ?a=API_GenAddRecordForm"  will pop up an Add Record form for a human user to complete and manually save.  That could only be used as the very last step in an API Button.

    ?a=API_AddRecord"  will create a record.

    You want to use the latter API
    • IvanWeiss's avatar
      IvanWeiss
      Qrew Captain
      I actually do have that, I changed it to gen addrecordform in an attempt to troubleshoot to see if it ever showed the form.  It does not show the form and it does not add the record
    • IvanWeiss's avatar
      IvanWeiss
      Qrew Captain
      It is that same code, I just fixed that one line you mentioned.  But it is not running that add API

      //Button Functionality:
      //1.  Change the stage of the opportunity to won
      //2.  Set the Date Won to Today
      //3.  Check to see if opportunity is of type design.  
      //      If true, assign a task to Lisa to create the sales order.
      //4.  Redirect back to the same form to display the record with updates.
      //*******************************************************************************************************************

      //Step 1 and 2
      var text urlOne = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
                                          "&rid=" & [Record ID#] &
                                          "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                          "&_fid_9=Won" &
                                          "&_fid_23=" & URLEncode(Today());

      //Step 3 - Build urlTwo variable if the type is design.  This assigns the sales order creation to lisa as a task.
      var text urlTwoIfDesign = URLRoot() & "db/" & [_DBID_TASKS] & "?a=API_AddRecord" &
                                      "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                      "&_fid_31=" & URLEncode(ToUser("ljording@elitestudioe.com")) &
                                      "&_fid_36=" &URLEncode("Task created automatically through Opportunity Win Button") &
                                      "&_fid_9=" & URLEncode(ToWeekdayN(Today())) &
                                      "&_fid_12=" & [Record ID#] &
                                      "&_fid_21=" & [Project] &
                                      "&_fid_24=Active" &
                                      "&_fid_38=" & URLEncode(ToText(ToUserList([Project Solutions T1],[Project Solutions T2]))) &
                                      "&_fid_23=Opportunity" &
                                      URLEncode("&_fid_83=Not Applicable") &
                                      "&_fid_6=Create Sales Order - Design Opportunity";
                                      
      //Step 3 - Build urlTwo variable if the type is build.  THE FOLLOWING IS A COPY OF THE ABOVE AS I DID NOT BUILD THE LOGIC OUT YET


      var text urlTwoIfBuild = URLRoot() & "db/" & [_DBID_TASKS] & "?a=API_AddRecord" &
                                      "&apptoken=c5gchf9bhwx6umbd2ii5zdqtb5x8" &
                                      "&_fid_31=" & URLEncode(ToUser("ljording@elitestudioe.com")) &
                                      "&_fid_36=" &URLEncode("Task created automatically through Opportunity Win Button") &
                                      "&_fid_9=" & URLEncode(ToWeekdayN(Today())) &
                                      "&_fid_12=" & [Record ID#] &
                                      "&_fid_21=" & [Project] &
                                      "&_fid_24=Active" &
                                      "&_fid_38=" & URLEncode(ToText(ToUserList([Project Solutions T1],[Project Solutions T2]))) &
                                      "&_fid_23=Opportunity" &
                                      URLEncode("&_fid_83=Not Applicable") &
                                      "&_fid_6=Create Sales Order - Design Opportunity";
                                   
      //Step 4
      var text redirect = URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#];
                                          
      //URL Execution
      Case(true,
      [Opportunity Type] = "Design", $urlOne & URLEncode($urlTwoIfDesign) & "&rdr=" & URLEncode($redirect),
      [Opportunity Type] = "Build", $urlOne & URLEncode($urlTwoIfBuild) & "&rdr=" & URLEncode($redirect)
      )