Skip to main content
Question

Batch Update ""Display As"" Property

  • October 24, 2018
  • 0 replies
  • 92 views

It is my understanding that you cannot use the QuickBase API to change a field's type. However, API_SetFieldProperties has been quite the time saver when working with large groups of similar fields. 

One thing I haven't been able to do, is find a way to update the "Display As" field property via the QuickBase API. Is there a reason this field is not updatable via the API?

Or is the API parameter named as such that it would not be readily apparent?

Thanks!
This topic has been closed for replies.

  • Quickbase Alumni
  • October 25, 2018
The field name is the "Display As". I wish there was a different field for "Display As" that we can use for forms and reports, dynamic filters and so on, but alas, Quick Base doesn't have that yet. I have requested for this feature on User voice though.

  • Quickbase Alumni
  • November 2, 2018
Just create your own API modeled off the native action GenChangeFieldType. This is called the Be The API technique modeled off of the Be The Bike patent:


Be The Bike! From the Patently Absurd Inventions Archive
http://totallyabsurd.com/bethebike.htm

Towards this end write a function which returns a promise with this signature:
function changeFieldType(dbidTable, fid, type) {   return Promise.resolve(     $.get(dbidTable, {       a: "GenChangeFieldType",       BUT: "CONVERT+DATA",       D0: type,       fid: fid     })   ).then(function() {     return "it certainly worked!";   }); }
Set the parameters:
var dbidTable = "your table dbid";
var fid = "6";
var type = "PC";
And call the function:
changeFieldType(dbidTable, fid, type)
  .then(function(response) {
    console.log(response);
  });
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=681

  • Quickbase Alumni
  • November 3, 2018
I wanted to add to my answer as I did not address the issue of using the code for a "Batch Update" as your title mentioned. The code I posted included a function changeFieldType() that changed the type of a single field. You might think that you could just call this function multiple times to make a batch update to multiple fields. However, if you tried this on a large number of fields you might well encounter a problem as your browser may choke when making so many simultaneous network requests. Luckily, there is a simple solution which can be extended and applied to much larger automation pipelines.

Note that the original code always returned a promise that resolved to the string "it certainly worked!". This was done because the native action GenChangeFieldType changes the field type on the backend and returns an unstructured HTML page as opposed to a well structured XML response. We could rip through the returned HTML page and scrape out some information indicating the action completed successfully or not but it probably isn't worth the extra effort because short of an error in the parameters the operation will almost always be successful. If you did want to process the HTML response the function would look something like this: 
function changeFieldType(dbidTable, fid, type) {
  return Promise.resolve(
    $.get(dbidTable, {
      a: "GenChangeFieldType",
      BUT: "CONVERT+DATA",
      D0: type,
      fid: fid
    })
  ).then(function(response) {
    return <extract some data from the HTML response>;
  });
}
If we wanted to do a batch update on multiple fields we might have a array of fids:
var fids = ["6", "7", "8", "9"];
Then we might call changeFieldType() multiple times in succession like this:
changeFieldType(dbidTable, fid[0], type)
  .then(function(response) {
    console.log(response);
    return changeFieldType(dbidTable, fid[1], type)
  })
  .then(function(response) {
    console.log(response);
    return changeFieldType(dbidTable, fid[2], type)
  })
  .then(function(response) {
    console.log(response);
    return changeFieldType(dbidTable, fid[3], type)
  })
  .then(function(response) {
    console.log(response);
  })
But clearly this approach will not work if you have say 100 fields to convert as the code would be repetitious and lengthy. If only we could use some type of a for loop to structure this chain of promises.

Well it turns out that there is a new feature in JavaScript that allows you to do precisely this. Here is some additional code that uses something called an "asynchronous generator" function named changeFieldTypes (nb this function name is plural and it takes an array of fids):
async function* changeFieldTypes(dbidTable, fids, type) {
  for (var i = 0; i < fids.length; i++) {
    var fid = fids;
    yield await changeFieldType(dbidTable, fid, type);
  }
}
for await (const response of changeFieldTypes(dbidTable, fids, type)) {
  console.log(response);
}
I will skip the technical details in this post but you can read more about Asynchronous Generators here:

Asynchronous Generators and Pipelines in JavaScript
https://dev.to/nestedsoftware/asynchronous-generators-and-pipelines-in-javascript--1h62

The bottom line is that using these techniques (jQuery and ES6 Promises along with Asynchronous Generators etc) you can create complex pipelines of processing to automate just about anything and the resulting code will be extremely short.

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=682