Hey there,
I've built a promise that filters an array of objects for a match on one of the properties, it then first resolves or rejects based on whether it finds the match and then on resolve it parses one of the properties of the object (which is an array).
The Run Script looks like this:
`module.exports = async function(data) {
const filterData = (data) => {
return new Promise((resolve, reject) => {
const filteredData = data.filter(item => item.id === "board_relation50");
if (filteredData.length === 0) {
reject(Error('No column found with the id "board_relation50". Perhaps the column ID is incorrect?'));
} else {
try {
const parsedData = JSON.parse(filteredData[0].value);
resolve(parsedData);
} catch (error) {
reject(Error('No linked Project Found. Try linking a project to the item and try again.'))
}
}
});
}
var array = {{get_monday_columns.data.data.items[0].column_values}};
return filterData(array)
.catch(error => console.log(error))
}`
which works a treat when it resolves but when the second reject kicks in 'no linked Project found...' nothing happens. I've tried this in VS code and the reject works fine but I'm not sure how to make it work for module.exports functions.
the initial array is:
[ { "title": "Project", "text": "Album Campaign", "value": "{\"linkedPulseIds\":[{\"linkedPulseId\":78678345}]}", "id": "board_relation50" } ]