# How can you copy the content of a field identified by name into a variable?

**URL:** <https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118>\
**Category:** Questions\
**Tags:** scripting\
**Created:** [May 10, 2024, 6:27pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118 "2024-05-10T18:27:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Massimo](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/massimo/32/2477_2.png) [@Massimo](https://the.fmsoup.org/u/Massimo)\
**Post date:** [May 10, 2024, 6:27pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118/1 "2024-05-10T18:27:12Z")

</div>

I've imported a file from excel, a bad one. I Have 100 column with dates named date1, date2, date3,....  
The target is to set all this dates in a multi field. To make it easy I would like to get in every field by the name of the field and set the text (date in the field) in a variable.  
I can't find a way to get the field by name. I tried with SQL.GetFieldAsText but it looks complicate and i'm not secure it's the right way.  
Do you have any suggestion?  
Tankyou

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [May 10, 2024, 7:04pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118/2 "2024-05-10T19:04:23Z")

</div>

I can't say that I have completely followed/understood your post.

But, it makes me think that perhaps one or more of the following could be of some help:

- The [GetField](https://help.claris.com/en/pro-help/content/getfield.html) function

- The [GetFieldName](https://help.claris.com/en/pro-help/content/getfieldname.html) function

- The [Set Field by Name](https://help.claris.com/en/pro-help/content/set-field-by-name.html) script step

---

<div class="post-metadata">

**Author:** ![jwilling](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jwilling/32/256_2.png) [@jwilling](https://the.fmsoup.org/u/jwilling)\
**Post date:** [May 10, 2024, 7:12pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118/3 "2024-05-10T19:12:05Z")

</div>

I'm a bit unclear too, but a first step might be to query all the fields in a given table via ExecuteSQL. You can even narrow this query to find only date/timestamp/time fields etc if you wish, and skip calculated fields [(all up to you)](https://www.databuzz.com.au/using-executesql-to-query-the-virtual-schemasystem-tables/).

`ExecuteSQL ( "SELECT fieldname from filemaker_fields WHERE tablename = ?" ; "" ; "" ; Get ( LayoutTableName ) )`

And then, for example, if you want to get all the values for the current record into a single value you could write something like this:

```auto
While ([
	~fields = ExecuteSQL ( "SELECT fieldname from filemaker_fields WHERE tablename = ?" ; "" ; "" ; Get ( LayoutTableName ) ) ;
	~count = ValueCount ( ~fields ) ;
	~res = "" ;
	~i = 0
];
~i < ~count ;
[
	~i = ~i + 1 ;
	~field = GetValue ( ~fields ; ~i ) ;
	~val = GetField ( ~field ) ;
	~res = List ( ~res ; ~field & ": " & ~val )
] ;
~res
)

/*
date1: 1/2/2024
date2: 2/3/2024
date3: 3/4/2024
...
*/

```

---

<div class="post-metadata">

**Author:** ![Massimo](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/massimo/32/2477_2.png) [@Massimo](https://the.fmsoup.org/u/Massimo)\
**Post date:** [May 10, 2024, 7:42pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118/4 "2024-05-10T19:42:14Z")

</div>

Getfield!!!!!!!!!!!!!!! 💡 💡 💡 💡  
you understood well! Thank You.  
I'm using the italian version and sometimes it's hard to find what i Need.  
I'm sorry for the stupid question 😵‍💫. Thank u so much for the patience and the support. 😃

Have a nice weekend 🤗  
Massimo

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [May 10, 2024, 10:47pm UTC](https://the.fmsoup.org/t/how-can-you-copy-the-content-of-a-field-identified-by-name-into-a-variable/4118/5 "2024-05-10T22:47:18Z")

</div>

Not a stupid question in the least.

I am certain that I speak for more than just myself when I say that I am glad that you asked. 👍🏼
