Inmagic Forums
Inmagic Forums
Scripting
help with script to remove some text and recreate field|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
Hi, I am struggling with a script and would appreciate help. I'm still a JavaScript novice (after 4 years!)
I have text in a multiple-entry field that displays on a report like this (the pipe character is set to be the separator text): rbutner on 2006-Apr-25 on 4:34:46 PM|lgall on 2004-Aug-30 on 1:19:50 PM|jbraun on 2004-Nov-5 on 1:40:49 PM I want to get it to look like this: rbutner on 2006|lgall on 2004|jbraun on 2004 I've gotten part-way there but now I'm stuck (note: I'm doing this on the desktop, not the Web). This is what I have: function onRecordOpen() { var entryLong = Form.boxes("nYear").content; nameYeararray = entryLong.split("|"); for (i = 0; i < nameYeararray.length; i++) { nameRow = nameYeararray[i].split("-"); nameRowshort = nameRow[0]; Application.message(nameRowshort); } Form.boxes("nYear").content = nameRowshort.join("|"); } I can tell from the Application.message command that nameRowshort has the right values in it, but I can't figure out where to put the join statement to put it all back together. Thank you in advance. Zoe |
|||
|
You're just about there, Zoe.
Your major problem is that you can't call join() on a variable of type string, which is what nameRowshort is; you can only call join() on an array. So, you need to add nameRow[i] to an array variable then join that array into a final string to assign to nYear.content. By the way, it's always good practice to define your function outside of onRecordOpen() and name it after the one task it performs. This improves readability and reusability of your code.
function onRecordOpen() {
shortenNameYearEntries();
}
var shortenNameYearEntries = function() {
var entryLong = Form.boxes("nYear").content;
var nameYearArray = entryLong.split("|");
var shortenedArray = [];
for (var i = 0; i < nameYearArray.length; i++) {
shortenedArray[shortenedArray.length] = nameYearArray[i].split("-")[0];
}
Form.boxes("nYear").content = shortenedArray.join("|");
}
Peter Tyrrell, MLIS Director and Lead Developer Andornot Consulting Inc. http://andornot.com/about/developerblog http://twitter.com/andornot |
||||
|
Thank you Peter, it worked perfectly and now I have a better grasp on arrays.
|
||||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|
Inmagic Forums
Inmagic Forums
Scripting
help with script to remove some text and recreate field
