Tuesday, May 11, 2021

#1 2021-04-24 02:57:06 am

ldicroce
Member
Registered: 2017-11-25
Posts: 235

Update Record values

Dear all,
I have to admit I have problems in processing records ...
My question is: how can update Record1 with values of Record2?
If I have Record1 and Record2 as detailed below:
set Record1 to {a:1, b:3, c:5, d:7, e:11}
set Record2 to {b:30, d:70, e:11}

How can I use the values of Record2 to update those (an only those) on Record1, so that my result should be:
--> Record1 as {a:1, b:30, c:5, d:70, e:11}

Thanks !

Offline

 

#2 2021-04-24 03:12:25 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5381

Re: Update Record values

Hi.

If Record2 only contains properties that are in Record1, you can concatenate Record1 to it:

Applescript:

set Record1 to {a:1, b:3, c:5, d:7, e:11}
set Record2 to {b:30, d:70, e:11}

set Record1 to Record2 & Record1
--> {b:30, d:70, e:11, a:1, c:5}

You can also do this if Record2 has properties which aren't in Record1, but the result will have the additional properties from Record2. Basically, if you concatenate two records, the result will have the properties from both records, with the values from the left-hand record being used where the labels are the same.

Applescript:

set Record1 to {a:1, b:3, c:5, d:7, e:11}
set Record2 to {b:30, d:70, e:11, z:"Hello"}

set Record1 to Record2 & Record1
--> {b:30, d:70, e:11, z:"Hello", a:1, c:5}}


NG

Offline

 

#3 2021-04-24 04:47:08 am

ldicroce
Member
Registered: 2017-11-25
Posts: 235

Re: Update Record values

Thanks a lot!

That's exactly what I was looking for. Thanks !

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)