Skip to main content
← Data, API & Backend
Data, API & Backend November 17, 2022 · 2 replies

Autocode script to check last page - conditional state pages

Archived from the Bravo community forum (2021–2026). Some answers may refer to older versions of Bravo.

Hi Community! I watched a video by on youtube https://www.youtube.com/watch?v=o4eChy6GrS4, where there was an example of how to return to the last page once the guide is completed (with different guide lengths).

We have a similar set-up in our app, however, I am stuck with the Autocode script and there is no full visibility of it on the video, because of  's pretty face 😅. 

My main questions are:

  1. Is it possible to get access to the script shown in the video by any chance?

  2. Also, will it be possible to see the airtable set up for this, to understand the field names and relation to the script?

  3. What are the steps to connect the API to the end pages, after the script is written, is it done via Airtable or Autocode and how?

Or if anyone here, did a similar thing, could you please help me out?

2 replies

app.monster November 18, 2022

Hi Jane,
glad you watched the video :) You can get the script of course (as mentioned in the comments). However, please note that this is not the best setup anymore. First, try to work with the conditional logic in Bravo or try the approach from my Halloween video.
Anyway, here is the code:

const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});

let result = {airtable: {}};

result.airtable.record = await lib.airtable.query['@1.0.0'].records.retrieve({
baseId: `YOUR_ID`,
table: `YOUR_TABLE`,
id: `${context.params.guideId}`,
});

//if Airtable record starts with "$" return 400, else return page content
if (startsWith(result.airtable.record.fields[`Page${context.params.page}Txt`], "$")) {
return {
statusCode: 400,
body: JSON.stringify({
error: {
message: 'Empty page',
},
}),
headers: {
'Content-Type': 'application/json',
},
};

} else {
console.log(`guide: ${result.airtable.record.fields.GuideName}, page:${context.params.page}`);
//return necessary data to be used in Bravo
return {
pageText: result.airtable.record.fields[`Page${context.params.page}Txt`],
pageImage:
result.airtable.record.fields[`Page${context.params.page}Img`][0].url,
guideName: result.airtable.record.fields.GuideName,
ID: context.params.guideId,
};
}

function startsWith(str, text) {
return str.lastIndexOf(text, 0) === 0;
}

Wrote something in this thread and want it removed? Request removal

Still stuck?

Ask the community on Discord

This archive is read-only. New questions, office hours and product updates now happen in the Bravo Discord.

Join the Discord