Home » Developer & Programmer » Forms » adding text to a field (Developer suit 10g)
adding text to a field [message #655588] Mon, 05 September 2016 00:04 Go to next message
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 Go to previous messageGo to next message
Littlefoot
Messages: 21806
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 #655590 is a reply to message #655589] Mon, 05 September 2016 04:00 Go to previous messageGo to next message
kumarravik
Messages: 32
Registered: January 2016
Location: delhi
Member
Thank you for the inputs.
It's the business requirement only. They want that manual text (#Monday) to work as a flag when data is sent to another system (SAP, mainframe etc) (for some indication).

It will be better (not necessarily) if i will be able to hide this processing so that this extra text will be shown only at query time.

As per your suggestions, best option is to define the trigger at database level. I am thinking about the option where I should use a form level trigger that should be called only once (while committing the records).
Re: adding text to a field [message #655591 is a reply to message #655590] Mon, 05 September 2016 04:05 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I see; well, in that case, I'd suggest you to create a NEW column and store that value ("#Monday" or whatever) into it. Keeping two pieces of information in a single column smells like a (lot of) trouble later.
Re: adding text to a field [message #655592 is a reply to message #655591] Mon, 05 September 2016 04:14 Go to previous messageGo to next message
kumarravik
Messages: 32
Registered: January 2016
Location: delhi
Member
Yeah, That's what I suggested too, but they asked me to find a way to utilize the text field to add the text Sad .

then only I am finding a way to sort this out.
Re: adding text to a field [message #655596 is a reply to message #655592] Mon, 05 September 2016 07:14 Go to previous messageGo to next message
cookiemonster
Messages: 13917
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 #655654 is a reply to message #655596] Wed, 07 September 2016 01:55 Go to previous messageGo to next message
kumarravik
Messages: 32
Registered: January 2016
Location: delhi
Member
I have added another condition to resolve this issue.
The sql code will check if it already has string like #Monday , if yes then no need to concatenate the text.
that will be helpful.

I have one another query related to "display item". The display item displays a message on whenever user enters any data in a text box. I want the message to be omitted when the cursor moves to another text item or field. The display item should display message only till the particular text_item is in focus or receiving inputs.




Re: adding text to a field [message #655669 is a reply to message #655654] Wed, 07 September 2016 03:07 Go to previous messageGo to next message
cookiemonster
Messages: 13917
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 #655673 is a reply to message #655669] Wed, 07 September 2016 05:44 Go to previous messageGo to next message
kumarravik
Messages: 32
Registered: January 2016
Location: delhi
Member
Thanks,

so i have to get the property then do the logic. tried to write a sql here for the same. do you think it will work (Haven't tried yet)?

Appreciate your inputs.

declare

curr_rec boolean :=get_block_integer(blk1.textItem1, current_record);

begin

if curr_rec ==1

disp_item :='display the message';
else

disp_item :=null;

end if;
end;
Re: adding text to a field [message #655674 is a reply to message #655673] Wed, 07 September 2016 08:19 Go to previous messageGo to next message
cookiemonster
Messages: 13917
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.
Re: adding text to a field [message #655676 is a reply to message #655654] Wed, 07 September 2016 13:18 Go to previous messageGo to next message
Littlefoot
Messages: 21806
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
kumarravik

I have one another query ...
Reinventing the wheel, are we?

Stuff you're talking about can be found in item's Property Palette window, at the bottom of the list, and it is called a hint. For your happiness, there's the tooltip property as well. You can put the same text into both of them.
Re: adding text to a field [message #655692 is a reply to message #655676] Thu, 08 September 2016 04:24 Go to previous message
kumarravik
Messages: 32
Registered: January 2016
Location: delhi
Member
thank you both for your help. your suggestions were helpful.

I should ask one query in one thread only :)Smile
Previous Topic: vertical scroll bar going to first column when I click down
Next Topic: To erase value when cursor leaves the field
Goto Forum:
  


Current Time: Thu Mar 28 08:17:17 CDT 2024