Discussions

Expand all | Collapse all

Best practice - Updating Record ID after a record save

  • 1.  Best practice - Updating Record ID after a record save

    Posted 16 days ago

    I'm looking for the best practice to retrieve the Record ID in JavaScript, after having created a new record

    in a table.

       For convenience I have posted the specific code snipplet below:

    /** Debug purposes **/ dump(parms); if (parms.partner_rid) { /** * save QuickBase data for this file upload */ $.ajax({ url: "/apps/insurance_uploads/code/upload_insurance_data.php", type: "post", data: parms, dataType: "json", success: function (row_id) { if (row_id == "NULL" || row_id == "") { /** * upload was unsuccessful */ fn_remove_uploaded_file(files[0]['url']); $("#modal-upload-failed").modal({ closeClass: 'icon-remove' }); fn_add_gritter('Unable to complete upload.', 'Your upload was unsuccessful. Please review your actions (did you remember to select an "upload type"?) and try again or call <b>248.688.0024</b> and press "2" for assistance.', 'fa-bomb', 'faa-pulse animated', true); } else { /** * upload successful */ fn_add_gritter('Confirmation (Row ID): ' + row_id, parms.file_name + ' has been successfully uploaded.<br/>(' + parms.doc_name + ').<br/><br/>Mouse over this alert and click x to close it.', 'fa-bell', 'faa-wrench', true); /** 10/04/20 - Earl - Added coding to create the companion Document Upload record **/ $.ajax({ url: "/apps/insurance_uploads/code/update_documentupload_data.php", type: "post", data: parms, dataType: "json", success: function (row_id) { fn_add_gritter('Confirmation (Row ID): ' + row_id, parms.file_name + ' had a companion Document Upload record successfully created.<br/><br/>Mouse over this alert and click x to close it.', 'fa-bell', 'faa-wrench', true); } }); } }, failure: function () { /** * unsuccessful doc info upload! remove uploaded file */ fn_remove_uploaded_file(files[0]['url']); $("#modal-upload-failed").modal({ closeClass: 'icon-remove' }); fn_add_gritter( 'Unable to complete upload.', 'Your upload was unsuccessful. Please review your actions and try again or call <b>248.688.0024</b> and press "2" for assistance.', 'fa-animated', 'faa-ring', true); } //async: false }); } else { //alert("first pass"); } } else { /** * this path is taken on initial load, * so no action since file[0] is empty */ }


    Any assistance would be greatly appreciated.

    Thanks,

    Earl



    ------------------------------
    Earl Adkins
    ------------------------------


  • 2.  RE: Best practice - Updating Record ID after a record save

    Posted 13 days ago
    Hi Earl - could you help us with what the business case here is you are trying to achieve and where this code is? Are you putting this in a code page? If so, its very easy to execute a query after the save.

    ------------------------------
    Harrison Hersch
    ------------------------------



  • 3.  RE: Best practice - Updating Record ID after a record save

    Posted 12 days ago

    Hi Harrison,

       The business case is this:

    Currently our Deployment Partners are required to provide Insurance Certificates.  This is currently being provide to us via email.
    In the faith of automating more processes we are moving to allow the Deployment Partners to upload their Insurance Certificates
    along with the respective information related to them.

      The code resides in a jquery.fileupload-ui.js page which is accessed via an ajax POST to the specific php pages.

    Currently after the form is filled out by the Deployment Partner they are allowed to select a file (Insurance Certificate) for upload and prompted to choose the Upload type (Insurance Coverage Type).

      Once the upload button is pressed a QB record is added to an Insurance table with the form data they provided.  If successful the next process executes uploading the file (Insurance Certificate), a record 'add' to the Document Uploads table returning the Row-ID.
    There is a text field in the Document Uploads table called 'QuickBase RID'.  This is slightly misleading as it is a reference field that is text.

      The problem is I am having difficulty getting the 'QuickBase RID' field to update with the returned Row-ID from the Document Upload.
    I have included the QB add and update code below:

    <?php set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"]); require_once "common/QuickBase/classes/QuickBaseUpdate.class.php"; foreach ($_REQUEST as $k => $v) { $_REQUEST[$k] = urldecode($v); } $TRUE_VALS = array("yes", "Yes", "true", "True", "On", "on", 1, "1", True); /** * params come from function "_renderDownload" in file "jquery.fileupload-ui.js" */ $qb_table = isset($_REQUEST["qb_table"]) && $_REQUEST["qb_table"] > "" ? $_REQUEST["qb_table"] : "bmtpe4qh3"; // QuickBase Table name $qb_rid = isset($_REQUEST["qb_rid"]) && $_REQUEST["qb_rid"] > "" ? $_REQUEST["qb_rid"] : "unknown"; // QuickBase Record ID $partner_rid = isset($_REQUEST["partner_rid"]) && $_REQUEST["partner_rid"] > "" ? $_REQUEST["partner_rid"] : 0; // partner RID $coverage = isset($_REQUEST["coverage"]) && $_REQUEST["coverage"] > "" ? $_REQUEST["coverage"] : "Automobile"; // coverage $doc_type = $coverage; // doc_type $doc_name = isset($_REQUEST["doc_name"]) && $_REQUEST["doc_name"] > "" ? $_REQUEST["doc_name"] : "unknown"; // document (original) name $file_name = isset($_REQUEST["file_name"]) && $_REQUEST["file_name"] > "" ? $_REQUEST["file_name"] : "unknown"; // file name $file_link = isset($_REQUEST["file_link"]) && $_REQUEST["file_link"] > "" ? $_REQUEST["file_link"] : "unknown"; // path to file $uploaded_by = isset($_REQUEST["uploaded_by"]) && $_REQUEST["uploaded_by"] > "" ? $_REQUEST["uploaded_by"] : "Earl Adkins"; $uploader_email = isset($_REQUEST["uploader_email"]) && $_REQUEST["uploader_email"] > "" ? $_REQUEST["uploader_email"] : "eadkins@fedcap.com"; $partner_name = isset($_REQUEST["partner_name"]) && $_REQUEST["partner_name"] > "" ? $_REQUEST["partner_name"] : 0; // partner name /** now update the Documents Uploads info * * Update: 10/06/20 - Earl - Added to create a 'Documents Upload' record for the file */ $table_id = "bmtpe4qh3"; $rec = '[{' . '"Related Deployment Company":"' . trim($partner_rid) . '","Document Type":"' . trim('Insurance - ' . $coverage) . '","Document Name":"' . trim($doc_name) . '","File Name":"' . trim($file_name) . '","File Link":"' . trim($file_link) . '","Uploaded By":"' . trim($uploaded_by) . '","Uploaded On":"' . date("Y-m-d H:i:s") . '","Upload ":"' . trim($uploaded_by) . '","Related":"' . trim($partner_rid) . '","QuickBase Table":"' . $qb_table . '","Other Party":"' . 'n/a' . '","Contact Type":"' . 'n/a' . '","Assignee":"' . 'n/a' . '","Assignment Type":"' . 'n/a' . '"}]'; $qbo = new QuickBaseUpdate($table_id, "add", $rec); $rst = json_decode($qbo->json); $qb_rid = json_encode($rst[0]->{"rid"}); // return update_id or rid /** * $this->result = json_decode('{"action":"API_AddRecord","errcode":"0","errtext":"No error","rid":"97","update_id":"1368712078584"}'); */ /** unset($qbo); // try this to see if we need to clean up old objects -- may need to leave out iot access qb_rid later **/ echo $qb_rid; $QB_rid = $qb_rid; echo $QB_rid; /** 10/09/20 - Earl - Update the Document Upload record using the 'row_id' generated from the File Upload **/ $rec = '[{' . '"QuickBase RID":"' . $QB_rid . '"}]'; $qbu = new QuickBaseUpdate('bmtpe4qh3', 'upd', $rec); $rst = json_decode($qbu->json); $upd = json_encode($rst); unset($qbu); echo($upd->json);

    ------------------------------
    Earl Adkins
    ------------------------------