Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my method being called twice?
    primarykey
    data
    text
    <p>I'm working with HTML forms that are connected to a database via an REST API. The server work is handled with Coldfusion, mainly in cfscript syntax. </p> <p>The form data is submitted in two or more sets per form. Most of the forms are long and performance dictates submitting ~70 fields per set. Splitting the record between create and updates also allows for duplicate checking by passing the form response ID in the initial call and checking for it in subsequent updates as the form is completed. </p> <p>When an incoming form initializes the application, the form response ID is queried. If there's no match, then it's a new record. If there is a match, the record is updated using the database record ID. I currently have this logic set up in an if statement and two records are being created in the initial call. I've tried a few variations on attempts to solve this including checking other variables, switch statements, do/while loop, nested if statements, etc. In each case two records rather than one is created. Subsequent calls update the latest of the two records and no new records are created. </p> <pre><code>&lt;cfscript&gt; // Setup the qb object to call add and update methods qb = new components.qb(); // Setup query object. In this case we're passing Response ID parameters to compare against. This allows us to check whether the incoming request represents a new record or an update. qbQuery = new components.qbQue().qFieldValue(#qb_tableID#, #qb_token#, #uField#, #uValue#, #uList# ); // An array of returned records, empty if new record qbRecords = qbQuery.getQbRecords(); // The latest Record ID to edit qbLatest = qbQuery.getLatestRecord(); writeOutput("qbRecords is #arrayLen(qbRecords)# long! &lt;br&gt;"); if (arrayLen(qbRecords) == 0) { add_record = qb.addRecord(qb_tableID, qb_token, form_data); } else { edit_record = qb.editRecord(qb_tableID, qbLatest, qb_token, form_data_edit); } &lt;/cfscript&gt; </code></pre> <p>[EDIT] addRecord() function</p> <pre><code>public any function addRecord(qb_tableID, qb_token, form_data) { variables.qb_ticket = SESSION.qbTicket ; http method = "POST" result = "qbReturn" url = "#variables.qbUrl#/#qb_tableID#?act=API_AddRecord&amp;ticket=#variables.qb_ticket#&amp;apptoken=#qb_token#&amp;#form_data#" ; this.setUuid(CreateUUID()); this.setQbResult(XmlParse(qbReturn.Filecontent)); this.setQbAction(Trim(QbResult.xmlRoot.XmlChildren[1].XmlText)); this.setQbErrCode(Trim(QbResult.xmlRoot.XmlChildren[2].XmlText)); this.setQbErrText(Trim(QbResult.xmlRoot.XmlChildren[3].XmlText)); this.setQbRid(Trim(QbResult.xmlRoot.XmlChildren[4].XmlText)); this.setQbUpdateid(Trim(QbResult.xmlRoot.XmlChildren[5].XmlText)) ; return ( this ) ; } </code></pre> <p>[EDIT] The above function is refactored from the following createRecord() function. Among the changes the current addRecord() function passes data to the API in a URL where the old code submitted XML. That shouldn't be the issue but I'm calling it out as a significant difference.</p> <p>The other significant difference is that createRecord() doesn't create two records.</p> <pre><code>&lt;cffunction name="createRecord" returntype="any" access="public" output="false" description="Create new record"&gt; &lt;cfargument name="qbURL" type="string" required="true" /&gt; &lt;cfargument name="tableID" type="string" required="true" /&gt; &lt;cfargument name="newRecord" type="xml" required="true" /&gt; &lt;cfargument name="theTicket" type="string" required="true" /&gt; &lt;cfargument name="theToken" type="string" required="true" /&gt; &lt;!--- Add Record ---&gt; &lt;cfhttp url="#qbURL#/#tableID#?" method="post" charset="utf-8" result="addRecord"&gt; &lt;cfhttpparam type="body" value="#newRecord#" /&gt; &lt;cfhttpparam type="Header" name="Content-Type" value="application/xml" /&gt; &lt;cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0"&gt; &lt;cfhttpparam type="Header" name="Content-length" value="#len(newRecord)#"/&gt; &lt;cfhttpparam type="URL" name="act" value="API_AddRecord"&gt; &lt;cfhttpparam type="URL" name="ticket" value="#theTicket#"&gt; &lt;cfhttpparam type="URL" name="apptoken" value="#theToken#"&gt; &lt;/cfhttp&gt; &lt;cfreturn addRecord.Filecontent /&gt; &lt;/cffunction&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload