Help

Re: Scripting: Can't seem to pass User field's value to another User field.

Solved
Jump to Solution
174 0
cancel
Showing results for 
Search instead for 
Did you mean: 
byrnes
6 - Interface Innovator
6 - Interface Innovator

I suspect this is a super easy thing to do, but I have been googling for over an hour now and all attempt to make this script function is seemingly failing.

 

const { recordId } = input.config();
const table = base.getTable('tbliyrxpGU6tkQgG7');

let record = await table.selectRecordAsync(recordId);

let user = record.getCellValue("Requestor (Airtable)");
console.log(user)

await table.updateRecordAsync(recordId, { "Requestor (AT)": { id: user }});

 

Requestor (Airtable) is a Lookup Field that is pulling in a User.
Requestor (AT) is a (Single) User field.

The console log shows that 'user' is indeed an object that has id, email, name. But no matter how I try to pass the user onto the actual user field, it won't take it. "Cannot accept the provided value."

12 Replies 12
Dan_Montoya
Community Manager
Community Manager

@byrnes , I prefer to use email address for identifying who asked for things.  This is alway unique and can be used to filter  interface views for people who do have accounts.  For example Screenshot 2024-05-17 at 2.08.57 PM.png

 

Screenshot 2024-05-17 at 2.09.55 PM.png

 

TheTimeSavingCo
18 - Pluto
18 - Pluto

Hm, not sure if you've already resolved this, but maybe try this? 

 

const { recordId } = input.config();
const table = base.getTable('tbliyrxpGU6tkQgG7');

let record = await table.selectRecordAsync(recordId);

let user = record.getCellValue("Requestor (Airtable)")[0];
console.log(user)

await table.updateRecordAsync(recordId, { "Requestor (AT)": { id: user }});

 

Link to base

Screen Recording 2024-05-20 at 2.49.48 PM.gif

I'm not sure why I needed it compared to yours, but yours got me there. I had to add a .id on user to make it work.

const { recordId } = input.config();
const table = base.getTable('tbliyrxpGU6tkQgG7');

let record = await table.selectRecordAsync(recordId);

let user = record.getCellValue("Requestor (Airtable)")[0];
console.log(user)

await table.updateRecordAsync(recordId, { "Requestor (AT)": { id: user.id }});


Thank you everyone!