Help

Re: Copy and Paste from Date to Link fields

Solved
Jump to Solution
14324 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Max_Brungardt
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m trying to make a script that will read from a Date field and copy and paste that data into a Link to field in the same table.
image
image
If there is a better way of doing this I am completely open to it. The end goal is to setup an Automation that will check for a change in date from the source and reflect that in a weekly report table.

1 Solution

Accepted Solutions
JonathanBowen
13 - Mars
13 - Mars

Hi @Max_Brungardt - for this to work, your date source field must be the primary field in the table (as this is what linked fields link to), so your set up would need to be something like this:

Screenshot 2020-11-05 at 17.15.24

If it is like this, then this simplified script will do the job:

let dateT = base.getTable('Dates');
let dateQ = await dateT.selectRecordsAsync();

for (let rec of dateQ.records) {
    let dateFieldID = rec.id
    await dateT.updateRecordAsync(rec, {
        'Date Link': [{id: dateFieldID}]
    })
}

The trick is that the linked field accepts an array of objects and each object is of the form:

{id: SOME_RECORD_ID}

See Solution in Thread

10 Replies 10
JonathanBowen
13 - Mars
13 - Mars

Hi @Max_Brungardt - for this to work, your date source field must be the primary field in the table (as this is what linked fields link to), so your set up would need to be something like this:

Screenshot 2020-11-05 at 17.15.24

If it is like this, then this simplified script will do the job:

let dateT = base.getTable('Dates');
let dateQ = await dateT.selectRecordsAsync();

for (let rec of dateQ.records) {
    let dateFieldID = rec.id
    await dateT.updateRecordAsync(rec, {
        'Date Link': [{id: dateFieldID}]
    })
}

The trick is that the linked field accepts an array of objects and each object is of the form:

{id: SOME_RECORD_ID}

This is great! Thank you. My only issue is that the table you show has only these two fields. My table has up to 30 fields and when I run it I get an error. Any ideas on how to work around this?

I don’t think the error will be related to the other fields (unless you are trying to update these other fields at the same time). What is the error you are getting?

image

Not sure, to be honest. It looks like an error unrelated to the script - connection issue perhaps? Can you post your full script - there might be an issue there.

The entire script (and only script as of now) is the one you put up just with my changed field and table names
image
And this is an example of how the Table could look
image

Ah, OK. The issue is the point that I noted in the first post. The “date source” field needs to be the primary field on the table for this to work. Your primary field is the property. Actually, this won’t make it error but you will get the property name in the linked field not the date source.

Taking a step back - what is it you are trying to achieve by putting the source date in the sale date? Is this just a snapshot of the initial date? It doesn’t need to be a linked field to do this, but you may have a different purpose.

The idea is that we have a Base with a Table of properties with sale dates and other information. We want another Base’s table to represent a grouping of sale dates of those properties. The important part is we don’t want to have to manually update those links. We just want to be able to change the date in the source Base Table and have that reflected in the second Base Table. I know this could easily be done by keeping the information in the same base, but this makes keeping track of reporting more difficult.

Thanks for all your insight.

OK, so like this?

Screenshot 2020-11-05 at 18.07.06

Screenshot 2020-11-05 at 18.07.12

Here, the date link field links to the second table.

This can be done with a script but you can’t create and link records in one go - you have to create it if it doesn’t exist, then link it.

I haven’t tried this out, but I think the way to do this is to use an automation that run a script. Have the automation based on “when a record is updated” and watch the source date field. Then, run the script. The script will be something like:

  • Get the new date source value
  • Query the dates table to see if the date already exists
  • If it does, get the ID. If it doesn’t, create it, then get the ID
  • Back on the properties table update the linked date field with the ID from the previous step.