Help

I am creating a new record and don't know how to populate the 'link' fields

Topic Labels: Scripting extentions
6441 11
cancel
Showing results for 
Search instead for 
Did you mean: 
Benito_Abraham
6 - Interface Innovator
6 - Interface Innovator

This is my code and I can’t populate the field ‘Activities’ which is linked to another table, the error is in line 24

image

11 Replies 11

Thank you for all your help, I just wanted you guys to know that I finally made it work and in case someone may find it useful, want to share the code with you:

// pick tables from your base here
let f_tasks = base.getTable(‘ACTIVITIES (CHECKLIST)’); // activities to be used as a template
let f_projects = base.getTable(‘EVENTS CATEGORIES’); // Events to be used as a template
let projects = base.getTable(‘Events’); // new Events table
let tasks = base.getTable(‘Events - Activities’); // new activities table
// prompt the user to pick a name for our new Event
let name = await input.textAsync('Please type here the Name of the Event you are about to create ');
// prompt the user to pick a template for our new Event
let category = await input.recordAsync(‘Please type here the category of the new Event’,f_projects);
// get all the records from the f_task table that meet the required event category
let JSONCategory = JSON.stringify(category);
let categoryView = JSONCategory.substring(JSONCategory.search(‘name’)+7,JSONCategory.length-2);
let result = await f_tasks.getView(categoryView).selectRecordsAsync();
// create the Event Record
let projectId = await projects.createRecordAsync({
‘Name’: name,
‘Category’: [category],
});

// create the Event-Activities Records
for (let record of result.records) {
var firstLoop = ‘Y’;
if(firstLoop == ‘Y’){
let queryResultT = await projects.selectRecordsAsync();
for (let recordx of queryResultT.recordIds) {
var recordt = [{id: recordx}];
}
firstLoop = ‘N’;
}
await tasks.createRecordAsync( {
‘Event’ : recordt,
‘Activities’: [record],
});
}
output.text(‘Done!’);

Andrew_O_Hoski
4 - Data Explorer
4 - Data Explorer

Came across this thread while looking for a way to link fields and find record ids. Here is the function I use to find a unique value and get the id.

async function findRecord(tableName, fieldName, searchValue)
{
    let returnID = '';
    let thisTable = base.getTable(tableName);
    let thisQuery = await thisTable.selectRecordsAsync();
    let thisRecords = thisQuery.records.filter(record => {
        let thisID = record.getCellValue(fieldName);
        return thisID == searchValue
    });

    for (let record of thisRecords){
        returnID = record.id;
    }
    return returnID;
}