Skip to main content
Question

Formula URL (button): Update field, Open Popup, close popup, Return to original page

  • August 1, 2023
  • 0 replies
  • 313 views

Forum|alt.badge.img+6

I want to:

  1. Hit a button
  2. Update a Field in that record
  3. Open a popup
  4. Close the popup (when a button is pushed)
  5. Return to the original page

I have steps 1, 2, 5 working with the below code on my URL-formula field.  I haven't been able to figure out steps  3,4 (the popup). 

var text RefreshPage = URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=<mytoken>&rid=" &[Record ID#] & "&_fid_10=" 
& Now() & "&rdr=" & URLEncode($RefreshPage)



------------------------------
Aaron B
ab1692@att.com
------------------------------
This topic has been closed for replies.

Forum|alt.badge.img+4

Hi Aaron,

You'll have to use a code page to accomplish this.  QB updated a year or so ago (maybe longer) and removed the workarounds to inject JS directly into a QB record, like the IOL technique.  Your URL field could lead you to a code page, which could do all of this for you.

Here's an example of something we implemented:

HTML:

<!DOCTYPE html>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<html lang="en-us">

<head>
  <meta charset="UTF-8">
  <title>EXAMPLE</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://YOURREALM.quickbase.com/db/DBID?a=dbpage&pagename=JS_PAGE.js"></script>
</head>

<body>
  <div id="loading">
  </div>
</body>
</html>

JS:

const queryString = window.location.search;
urlParams = new URLSearchParams(queryString);
const apptoken = urlParams.get('apptoken')
const mode = urlParams.get('mode')
const rid = urlParams.get('rid')
let tempToken

$(document).ready(function(){
	getTempUserToken("TABLEID").then(function() {
    let body = {
       "to": "TABLEID", // ID of table you're updating
       "data": [
         {
          "3": {
            "value": rid
          },
          "160": {
            "value": false
          }
         }
       ]
    }
    
    $.ajax({
      url: 'https://api.quickbase.com/v1/records',
      method: 'POST',
      headers: {
      	'QB-Realm-Hostname': 'YOURREALM.quickbase.com',
      	'Authorization': 'QB-TEMP-TOKEN ' + tempToken,
      	'Content-Type': 'application/json'
      },
      data: JSON.stringify(body),
      success: function(result) {
        alert("ALERT TEXT")
        window.history.go(-1) //other, more elegant ways of accomplishing this
      },
      error: function(result, textStatus, errorThrown) {
        alertError(result, textStatus, errorThrown)
      }
    })
  })
})


function alertError(result, textStatus, errorThrown) { // Error function for AJAX calls
  alert(textStatus + ': ' + result.responseJSON.message
+ ' - ' + result.responseJSON.description);
}


function closeWindow() {
  let newWindow = window.open('', '_self', ''); 
  newWindow.close();
  return false
}


/*---------------------------AUTHORIZATION---------------------------*/

let getTempUserToken = async (dbid) => {
  let promise = await $.ajax({
  url: 'https://api.quickbase.com/v1/auth/temporary/' + dbid,
  method: 'GET',
  headers: {
  'QB-Realm-Hostname': 'YOURREALM.quickbase.com',
  'QB-App-Token': apptoken,
  'Content-Type': 'application/json'
  },
  xhrFields: { withCredentials: true },
  })
  tempToken = promise.temporaryAuthorization
  console.log(tempToken)
}

CSS:

#loading {
  background: url('https://LINKTOYOURLOADINGGIF.gif') no-repeat top left;
  display: block;
  position: absolute;
  top: 125px;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: 9999999;
}



------------------------------
Chris Wheatley
------------------------------