Exit a repeat loop inside a tell block and go back in to continue the

I found the neat searchReplace handler I’m trying to use below in the text manipulation forum here. It isn’t working with this script for some reason. It does however step through all the records traversed in the loop and returns the correct result when the final line of code within the repeat loop is commented out. When this line is allowed to run it sets the value of the target field to the original, unchanged value. As mentioned above, when the line is commented out the correct result for each record is returned but trying to modify the target field breaks it. Scratching my head. Thanks in advance for any insights.



tell application "Portfolio"
	tell document 1
		tell gallery "Find Results"
			repeat with i from 1 to count of records
				tell record i
					set theName to value of field "Subject"
					my searchReplace(theName, "w/", "with ")
                                        --set value of field "SEO_Subject" to theName
				end tell
			end repeat
		end tell
	end tell
end tell

to searchReplace(thisText, searchTerm, replacement)
	set AppleScript's text item delimiters to searchTerm
	set thisText to thisText's text items
	set AppleScript's text item delimiters to replacement
	set thisText to "" & thisText
	set AppleScript's text item delimiters to {""}
	return thisText
end searchReplace


Model: Mac Pro 5,1
AppleScript: 2.1.2
Browser: Safari 534.57.2
Operating System: Mac OS X (10.6)

Hello.

You probably miss lines like this inside your tell record block

You really haven’t pulled off the value from the searchReplaceHandler, the string is passed by value, and hence won’t keep any changes.


set theName to my searchReplace(theName", "\w.", "With")

 set value of field "Subject" to theName

Thanks! Working now.