www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    Last entry / word
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
AT
Posted
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!
 
Posts: 65 | Location: Essex | Registered: Fri April 29 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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
 
Posts: 179 | Location: Vancouver, BC, Canada | Registered: Thu September 20 2001Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    Last entry / word