Help

Scripting Block Help

Topic Labels: Scripting extentions
3300 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Shane_Leidy
4 - Data Explorer
4 - Data Explorer

I have a scripting block setup to create a series of 50 linked records when needed. These act as a checklist workflow and are linked to the original project in the other table.

My only issue is trying to pull in the Single Select field for City to fill in the 50 linked records. I need the city to pull from the selectedEvent and not the checklist template.

// pick tables from your base here
let checklist = base.getTable(‘Project Workflows’)
let templateView = base.getTable(‘Project Workflows’).getView(‘Expansion Workflow Template’);
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = templateQuery.records;
let noChecklist = base.getTable(‘Ongoing Projects’).getView(’**Expansion Projects ALL’);

// Select Event to Create Checklist
let selectedEvent = await input.recordAsync(‘Choose Event to Create Checklist’,noChecklist);

// create the tasks
let createRecords = templateRecords.map( c => ({fields: {

    'Task Subject': c.getCellValue('Task Subject'),
    'Project Link': [selectedEvent],
    'Tasks': c.getCellValue('Tasks'),
    'Task Assigned To': c.getCellValue('Task Assigned To'),
    'RE Stage': c.getCellValue('RE Stage'),
    'Project Phase': c.getCellValue('Project Phase'),
    'Project Type': c.getCellValue('Project Type'),
    'Task #': c.getCellValue('Task #'),
    'City': THIS IS WHERE I HIT MY ERROR. I NEED THIS FIELD TO PULL FROM THE SELECTED RECORD, NOT THE WORKFLOW SUMMARY VEW WHERE THE TASKS ARE PULLING FROM.

}})
);

if(selectedEvent)await checklist.createRecordsAsync(createRecords)
else output.markdown("# Uh-Oh You didn’t select an event!")

output.text(‘Done!’);

4 Replies 4

Try something like selectedEvent.getCellValue('name of city field')

Shane_Leidy
4 - Data Explorer
4 - Data Explorer

Thanks for the suggestion, but it still gives me an error.

Screen Shot 2020-07-21 at 8.55.27 AM

What is the field type of the source for the city? Its read type might be different from the write type of the target field.

Are you sure the city exists as an option for the target field? If both the origin and source fields are single select fields, the fields might have different choice ids, even if the have the same choice names.

You can also look at my script for copying the value one field to another and see how it handles different field types.

I see you stated the City field is a single select, so you’ll need something like this:

selectedEvent.getCellValue('name of city field').map(x => ({name: x.name}))