Jan 10, 2024 08:54 PM
the script is not taking input as want to update values in linked field
code:
at main on line 58
Jan 12, 2024 07:52 PM
Hey @bharatsingh9808!
Give this a shot and lemme know how this works.
I'm not able to fully test it in a test environment, but the bones are solid:
const { recordId } = input.config();
const tables = {
audience: base.getTable("Target Audience SS")
};
const fields = {
recordId: "Record ID",
newsletter: "Newsletters Media Company",
podcast: "Podcast Media Company",
youtube: "YouTube Media Company",
media: "Media Company"
};
const trigger = await tables.audience.selectRecordsAsync({ fields: Object.values(fields) })
.then((q) => q.records.find(r => r.id === recordId));
let lookupFieldValues = {
newsletter: trigger.getCellValue(fields.newsletter)?.map(ref => ref.id) || [],
podcast: trigger.getCellValue(fields.podcast)?.map(ref => ref.id) || [],
youtube: trigger.getCellValue(fields.youtube)?.map(ref => ref.id) || []
};
let updateValue = (() => {
let idValues = Object.values(lookupFieldValues).flat();
if (idValues.length)
return [...new Set(idValues)].map(value => ({ id: value }));
})();
if (updateValue)
await tables.audience.updateRecordAsync(trigger, { [fields.media]: updateValue });
Jan 12, 2024 07:55 PM
A quick note that I forgot to include...
You have the following lines in your script:
const triggeringRecord = input.config();
const recordId = triggeringRecord.RecordModified;
For the script I just posted, you'll want to rename your `RecordModified` input variable to just `recordId`.