@Christoph posted something that caught my attention and stopped me from doing what I was supposed to be doing!
If you have a selection field in a record and you are creating records via Webhook and the incoming Webhook needs to add to the selection field a new option how do you do this? You could use something like An alternative to multi-selct fields and using AI to obtain Keywords
or you could do this:
The first part sets my Tape API Key
tape.setApiKey(collected_api_key_field_apikey_value);
Then we get the status from the incoming webhook:
// Extract the webhook status
const webhookStatus = jsonata('status').evaluate(webhook_payload_parsed);
We now get the App details, the number is your APP ID:
const a = await tape.App.get(39501);
We build a list of current status options - You need the field ID to replace mine:
const statusList = jsonata(`data.fields[field_id=370429].config.settings.options[].text`).evaluate(a);
Now we want to add the status option if it doesn’t exist:
if (!statusList.includes(webhookStatus)) {
// Update the app if the webhookStatus is not in the statusList
const r = await tape.App.update(39501, {
fields: [{
field_id: 370429,
config: {
label: "Status",
settings: {
options: [{
text: webhookStatus,
}]
}
}
}]
});
console.info('Status updated:', webhookStatus);
} else {
console.info('Status already exists:', webhookStatus);
}
either way, we want to add the webhook status to the new record so we put it into an output variable:
var_status = webhookStatus;
Then, we can create the new record as if the option had been there beforehand. The whole script looks like this:
tape.setApiKey(collected_api_key_field_apikey_value);
// Extract the webhook status
const webhookStatus = jsonata('status').evaluate(webhook_payload_parsed);
// Get the current app data
const a = await tape.App.get(39501);
// Extract the current status list
const statusList = jsonata(`data.fields[field_id=370429].config.settings.options[].text`).evaluate(a);
console.info(statusList);
// Check if the webhookStatus is in the statusList
if (!statusList.includes(webhookStatus)) {
// Update the app if the webhookStatus is not in the statusList
const r = await tape.App.update(39501, {
fields: [{
field_id: 370429,
config: {
label: "Status",
settings: {
options: [{
text: webhookStatus,
}]
}
}
}]
});
console.info('Status updated:', webhookStatus);
} else {
console.info('Status already exists:', webhookStatus);
}
var_status = webhookStatus;
To find the APP ID and field ID go into the developer information: