adding text to a field [message #655588] |
Mon, 05 September 2016 00:04  |
 |
kumarravik
Messages: 32 Registered: January 2016 Location: delhi
|
Member |
|
|
Hi,
I have one text item field, where i want to concatenate a text (fixed text for each time) value while saving the value in database.
like, if user enters "morning" and click on save, the value should be stored in database as "Morning #Monday".
i wrote a simple sql, for this operation on trigger "when_validate_item" and worked ok.
:text_item1 :=:text_item1 ||"#Monday";
However, there's one problem here.
if user realizes that he has mistype the spelling/text and modified into the correct one, the trigger fires again and add the text twice as "Morning #Monday #Monday morning"
Please suggest how to solve this issue. Appreciate your help.
|
|
|
Re: adding text to a field [message #655589 is a reply to message #655588] |
Mon, 05 September 2016 00:45   |
 |
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
First of all, why are you doing that? What business requirement are you trying to solve? Perhaps there's another (better?) way to do it so - please, could you explain it?
Anyway: consider using another trigger, instead of the WVI: an ON-INSERT and ON-UPDATE. These two replace default Forms processing, so you'd literally insert a record, manually:insert into some_table(col1, ...)
values (:text_item1 || ' #Monday', ...); If it is a multi-record block, you'd have to do it in a loop.
Another, probably a better option (which would, however, "hide" processing as it happens in the database and might confuse someone who didn't design the solution) is a BEFORE INSERT OR UPDATE database trigger which would do the concatenation.
Or, create another text database item which will be inserted into the database. Let users enter values into a non-database text item and reuse current WVI trigger::database_text_item := :text_item1 || '#Monday'; That might be the best option of all I mentioned.
Someone else might suggest yet another one(s).
|
|
|
|
|
|
Re: adding text to a field [message #655596 is a reply to message #655592] |
Mon, 05 September 2016 07:14   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Ask them what happens when a user edits the #Monday text. You've got no way of stopping them with this approach. Sure you can make it add a new #Monday at the end but this could get very silly very quickly.
It needs to be stored separately.
|
|
|
|
Re: adding text to a field [message #655669 is a reply to message #655654] |
Wed, 07 September 2016 03:07   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Only way I can think of doing that is to have a form level when-new-item-instance. Check in there if the current item is the one concerned, if it is populate the display item, otherwise set it to null.
|
|
|
|
Re: adding text to a field [message #655674 is a reply to message #655673] |
Wed, 07 September 2016 08:19   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
I've no idea what get_block_integer is, it's not listed in my (admittedly old) copy of the forms documentation.
Also your use of boolean is wrong.
Plus your original description doesn't suggest that the record number is relevant in any way.
|
|
|
|
|