Custom field type - workaround to make them more dynamic

Hi there,

There are cases when you want to populate the custom field type (list - dropdown) dynamically. In my case I populate them from a database. Unfortunately the URL specified to get the list does not support queryvars, so I came up with a workaround. Feel free to use it and enhance it (but please share enhancements).

I use different routes in nodeJS that ends in my case with a fieldtype, like:

router.post(“/master-detail/cf-column/timerange”, authenticationMiddleware, masterDetailController.cfTemplateColumns);

router.post(“/master-detail/cf-column/numeric”, authenticationMiddleware, masterDetailController.cfTemplateColumns);

router.post(“/master-detail/cf-column/color”, authenticationMiddleware, masterDetailController.cfTemplateColumns);

As you see the routes calls the same function (cfTemplateColumns). Inside this function I use the aud in the req.session to extract the last part of the URL and pass it to my SQL function inside masterDetailService.GetTemplateColumns.

async function cfTemplateColumns(req, res) {
try {
const { authorization } = req.headers;
if (!authorization && req.query) authorization = req.query.token;
const { accountId, userId, aud, exp, iat } = jwt.verify(authorization, process.env.MONDAY_SIGNING_SECRET);
req.session = { accountId, userId, aud, exp, iat };
} catch (err) {
res.status(401).json({ error: “not authenticated” });
}
//Use the aud field in the req.sessions as the last part contains the column type
const columnType = req.session.aud.split(“/”).pop();
columnList = await masterDetailService.GetTemplateColumns(req.session.accountId, columnType);
return res.status(200).send(columnList);
}

Have fun with it.

1 Like

@basdebruin does it again! :dark_sunglasses:

Thanks so much for sharing this workaround with the community! I really appreciate the help you’ve been providing all around the community and this is just another gem you’ve shared. Thanks for your continued effort in making this work for everyone - it’s much appreciated, trust me! :slight_smile:

-Alex