You may want to use:
Go to Field [Citations:Citation]
TextStyleRemove( Get ( ActiveFieldContents ) ; Underline )
Like this there is no need for the "Select All" step and you'd probably avoid the unexpected behaviour
Set Field [Citations:Citation ;TextStyleRemove( Get ( ActiveFieldContents ) ; Underline ) ]
Would seem even simpler and would avoid both changing the current position of the cursor and the need for this field to be present on the current layout when the script step executes.
thank you for your help. However i still encounter problems.
1. The solution PhilModJunk has proposed instead of removing text style removes everything. (However I would promise that when i checked it one month ago, it worked differently. I am completlly confused.)
2. The script I have written to remove highlighting from one word is deleting everything but this word.
Here is the file that ilustrates the problem.
The solution PhilModJunk has proposed instead of removing text style removes everything.
Better check your setup again. It works exactly as I specified, though I'd simplify it further to use:
Set Field [Citations:Citation ;TextStyleRemove( Citations:Citation ; Underline ) ]
I'd guess that the focus was in the wrong field when the script was executed. This last version doesn't need for the focus to be in the field.
PhilModJunk, my bad. You were right.
However I still have some problems with that function.
In my database I am selecting words from text. I should highlight them. There is a script that creates in a table words a new record out of selcted fragment of text in text table it also assignes Start Index and End Index to define the position of the word in text.
In the Text layout i have a portal with all words, that were selected from the text. I want to create a script to underline the word one is clicking on. The initial situation is presented on the Picture1 Script file (link is below).
I have created the following script:
Go to Related Record [ From table: “Words” ; Using layout: “Words” (Words) ]
Set Variable [ $Start; Value:Words::StartIndex ]
Set Variable [ $End; Value:Words::EndIndex ]
Go to Layout [ “Texts” (Texts) ]
Set Selection [ Texts::Text ; Start Position: $Start; End Position: $End ]
Set Field [ Texts::Text ; TextStyleAdd(Middle(Texts::Text;Get(ActiveSelectionStart);Get(ActiveSelectionSize));Underline) ]
However instead of underline the selcted word it delete everything but the selected word and it underlines it.
I would be really greatful for any ideas how to solve this problem.
It is doing exactly what you told it to do, not what you want it to do.
Set Field [ Texts::Text ; Left ( Texts::text ; $Start ) & TextStyleAdd(Middle(Texts::Text;$Start ;$End - $Start + 1 ;Underline) & Right ( Texts::text ; length ( Texts::text ) - $End ) ]
I put that together without testing. It should be close to what you want, but you may need to tweak the calculations a bit.
This approach does not require the set selection step.
Or you can keep set selection and use:
Insert Calculated result with your original expression.
I prefer set field over the "insert" script steps as set field can do the job even if the field is not on the current layout and does so without tripping script triggers that might be set up on the field.
BTW, the trick to using Insert Calculated Result in this context is to NOT specify the target field. When you don't specify a target field with a script step starting with "insert", the script step inserts the text at the current focus--which is what you want here.