Skip to main content
WolfShade
Legend
June 7, 2011
Question

CFAJAXPROXY and timing

  • June 7, 2011
  • 1 reply
  • 536 views

Hello, everyone.

I'm using CFAJAXPROXY to call CFC's via JavaScript, and I've come across what I believe to be a timing issue.

Basically what I'm trying to do is use the same form for both INSERT and UPDATE to a database.

If it's an INSERT, the ID field is set to 0; if it's an UPDATE, the ID field is set to whatever ID is associated with the data pulled from the database.  No problem.

I was using an IDENTITY field for the ID's but that created issues with another CFC (the one method that does either the INSERT or UPDATE, depending) so I've changed the ID columns so they are no longer IDENTITY - which means that I have to SELECT the max(ID)+1 for the next ID, if it's an INSERT.

I can't get the new ID when the form loads - who knows how many people will be using this form.  So I'm trying to set it so that when the form submits, if the ID is 0, THEN run the SELECT max(ID)+1 to get the new ID.

But the lag between calling the CFC and getting the result is causing me to set the ID variable to UNDEFINED.

Here is some code:

var gpi = new cfc_getProjectInfo();
     gpi.setHTTPMethod("POST");

function submitForm() {

     //blah blah blah

     if(thisValue == 0) { // If new base, get next BASE_ID
     gpi.setCallbackHandler(getNewBID);
     gpi.setErrorHandler(myerrorHandler);
     thisValue = gpi.getNewBaseID();
     }
     formObj[thisName] = thisValue;

     //blah blah blah

  }

function getNewBID(BID) {
     return BID;
     }

The CFC method is returning a string, the new ID.

Any suggestions?

Thanks,

^_^

    This topic has been closed for replies.

    1 reply

    Inspiring
    June 7, 2011

    My suggestion is to base your coldfusion code on your database, not the other way around.  Using an identity datatype was probably a good idea.  Changing it because you couldn't get some coldfusion code to work was a bad one.

    That being said, what type of db is it? 

    WolfShade
    WolfShadeAuthor
    Legend
    June 7, 2011

    SQL 2008.

    And a few of the CFC methods that I am using are not editable by me, but they are part of the requirements of this project, and they exist outside the root of the site - many different sites access them.  Part of a 'universal' approach to development.  Not my idea.

    Inspiring
    June 7, 2011

    A UUID created by Coldfusion might do the trick.