Skip to main content

 

I have a table with two columns: Url and QR Code.  I would like to run a script that will modify the QR Code field when the Url field changes.

I created an automation that fires a script when the Url changes.  I'm trying to determine how to modify the QR Code in the row that changed.

The script:

/**

* Generate a QR code from text, using QuickChart.io (https://quickchart.io/documentation/qr-codes/)

* @param {string} text The text to be converted.

* @returns {string} The QR code's URI

*/

const getQrCodeUri = ( text ) => {



const serialize = function(obj) {

var str = [];

for (var p in obj)

if (obj.hasOwnProperty(p)) {

str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));

}

return str.join("&");

}



const settings = {

text: text,

size: 150,

margin: 4,

dark: 'f00',

light: '0ff',

ecLevel: 'Q',

format: 'svg'

}

const qs = serialize(settings)



const baseUri = 'https://quickchart.io/qr'

const uri = `${ baseUri }?${ qs }`



return uri;



}



// input variables

let inputConfig = input.config();

let url = inputConfig.url;



// calculate QR code

const qrCodeUrl = getQrCodeUri(url);

console.log('qrCodeUrl',qrCodeUrl)



// update the QR Code field

?

 Do I pass the QR Code field as an input, then set its value or is there more to it?

You can upload an attachment field in Automation by passing a URL to it.
You would add the attachment field and then update the attachment field with the QR code image link in Automation.

I think you also may not use an image URL to display an image in Page Designer, etc. instead of an attachment. Too many accesses may cause the communication to be blocked in the worst case and the image may not be displayed.


I changed the script to return a Url:

 

/**

* Generate a QR code from text, using QuickChart.io (https://quickchart.io/documentation/qr-codes/)

* @param {string} text The text to be converted.

* @returns {string} The QR code's URI

*/

const getQrCodeUri = ( text ) => {



const serialize = function(obj) {

var str = [];

for (var p in obj)

if (obj.hasOwnProperty(p)) {

str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));

}

return str.join("&");

}



const settings = {

text: text,

size: 150,

margin: 4,

dark: 'ffffff',

light: '000000',

ecLevel: 'Q',

format: 'svg'

}

const qs = serialize(settings)



const baseUri = 'https://quickchart.io/qr'

const uri = `${ baseUri }?${ qs }`



return uri;



}



// input variables

let inputConfig = input.config();

let url = inputConfig.url;



if (url != null) {

// calculate QR code

const qrCodeUrl = getQrCodeUri(url);

output.set('qrCodeUrl', qrCodeUrl);

}

else {

output.set('qrCodeUrl', null);

}

 

Then I added an Update Record action, setting the Record ID to the trigger's Airtable record ID field, and the QR Code field to the QrCodeUrl function.


Reply