IvanWeiss
6 years agoQrew Captain
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)
)
//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)
)