|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
I have a field with multiple entries and I would like to extract the last entry to a new field. Does anyone have an example script to do this? Each entry is only one word so a script to extract and copy the last word would also be fine.
I can find plenty on copying first words or using just the first entry of a list in Scripts but nothing on this. I expect it would need some kind of an array but I just can't see what the command for last entry is Thanks! |
|||
|
An array is what you need, yes. Instantiate an array by splitting the field content on the entry separator. Then each element in the array is an entry, and it's a simple matter to retrieve the last (or first) one.
function Example()
{
/*
Get box content as string.
*/
var fieldValue = Form.boxes("myBox").content; // get field content
/*
Create array by splitting string on entrySeparator character.
*/
var entries = fieldValue.split(Application.entrySeparator);
/*
Array elements are retrieved with a zero-based count,
so the first element is entries[0] and the last element
is entries[entries.length - 1].
*/
var lastEntry = entries[entries.length - 1];
/*
Do something with last entry...
*/
Application.message("Last entry is '" + lastEntry +"'");
}
Peter Tyrrell, MLIS Senior Consultant Andornot Consulting Inc. http://www.andornot.com/about/developerblog |
||||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|

