Look at the Set Field By Name script step, as well as Get ( ActiveFieldName )
Find the field in Manage | Database | Fields and double click it.
Select the Auto-enter Tab
Click the option for a Calculation
Enter this text:
TextFormatRemove ( Self )
Clear the "Do not replace existing value..." check box
Note that you can copy and paste this expression to field after field without updating.
But to answer your specific question, You can use Set Field By Name in a script to set a field named in a variable to a value.
Set Field By Name [$FieldName ; //Put an expression here ]
The value of $FieldName has to be a "fully qualified field reference" in the TableOccurrencename::FieldName format such as Invoices::Description.
I think what you want to achieve should be at the database level, not in scripts.
If you want to do it by script (and add a trigger to each and every object, which I really wouldn't recommend), you can just use Set Field without specifying the field, and specify the calculation like : Trim ( TextFormatRemove ( Get ( ActiveFieldContents )) (for example, but you could also avoid leading/trailing carriage return)
If you want to do it at the database level, specify an auto enter calculation like
Trim ( TextFormatRemove ( self ))
and un check the Do not reevaluate checkbox.
(You can also create a custom function like text.clean ( text ) and use text.clean ( self ) in the auto enter, this will make it easier if you once want to change this calculation)
Thank you for reply, I never used Set field by name, and this is what I needed.
Do you prefer a Calculation field as you wrote (TextFormatRemove ( Self )) instead of a trigger in each field ?
Not a calculation field, but an auto-enter calculation on the text field.
This is preferred because, once set up on a field, all pasted formatting is removed automatically no matter what layout is used when pasting into the field.
With a scripted method, you have to do this over and over on every layout where this field is found and editable.
On the other hand, with a scripted approach, you can allow formatting of the text on some layouts and not others--I suppose there may be cases where that might be useful.