?
Solved

Set Default Value of a Field via the Web and a Formula

Posted on 2005-02-28
14
Medium Priority
?
1,028 Views
Last Modified: 2013-12-18
This is for the web.  I have two fields, one is a combobox with values 1-10 (MyField1) and the other is 100-200 (MyField2).  I have an embedded view that has Show Single Category set to MyField1 + MyField2 via a computed field that gets computed when the combobox's refresh the page.

Basically, the user can pick from the first list and then pick from the second list to form a number.  I need to combine that number into a field, that needs to be hidden.  

I have tried setting the default value of a field by: MyField1 + MyField2 and @SetField("FieldTotal"; MyField1 + MyField2).  I'm sure I am just off.
0
Comment
Question by:DawG25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 

Author Comment

by:DawG25
ID: 13422892
I want to use the combine values of the combobox's as a key in a later to be used @DBLookup
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13423171
Bear in mind that comboboxes are text based, not numeric.
You could set the default value for MyField1 to "1". Just as you would for a notes application.
Similarly set MyField2's default formula to "100".

Now set the hidden field (don't hide it yet for verification!) to computed, text and assign the formula: MyField1 + MyField2.

Easiest now it to set "refresh fields on keyword change" to both of the comboboxes. I'll cause a reload and even in the browser recompute the "hidden" field.
0
 

Author Comment

by:DawG25
ID: 13423190
That part works great.  How can I access the computed field though in my @DBLookup or put it into another FIELD.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DawG25
ID: 13423233
The other field is just text editable, not computted.
0
 

Author Comment

by:DawG25
ID: 13423544
I basically am combining the two combobox values to attempt to get data fro my view.  The combined numbers correspond to a document in my view.  If there is a document, I would like the title displayed in a text box, else nothing in a text box.  Hope this is clear enough.

Here is an example:

9 V    <--- think of the V as the combo box
110 V

Combined value: 9110
The title: Title2

My View

9109   Title1
9110   Title2
9111   Title3
0
 
LVL 3

Expert Comment

by:sravikiran
ID: 13425485
OK,

suppose the hidden field name is "FieldTotal". This field shoul dhave the following computed formula
MyField1 + MyFiield2

Now, suppose the field that you want to show the title is "Title". Use the following formula

Dtitle:= @DbLookup( "" ; <servername> : <databaseName>; <viewname>; FieldTotal ; Subject );
@if(@iserror(Dtitle);"";Dtitle);

The above formula assumes that you want to show the Subject of the document in the title field. You can substitute the last argument with the field name that you would like to show its contents in the title field.

In addition, you can use FieldTotal to show single category view
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13427086
Hi, I'm awake again....
sravikiran is right, but its not the whole story. I assume you are not all that expirienced yet in programming notes.

I assume you already have documtens ready holding the search keys (equivalent for FieldTotal) and the value to be retrieved. I'll refer to them as "Key" and "Title" resp. You'll need to put these in a view with (at least) two columns:
Col 1: Key (sorted or @DbLookup won't find anything!)
Col 2: Title

Name the view e.g. "(TitleByCode)". The brackets will hide the view for users.

The @DbLookup should now like like:
Dtitle := @DbLookup( "" ; ""; "(TitleByCode)"; FieldTotal ; 2);
@If(@Iserror(Dtitle);"";Dtitle);

The 2nd parameter ("") will tell @DBLookup to use the current database. Be carefull NOT to refer to a server in a web-based application!

The formula should work well in a computed (text) field.
0
 

Author Comment

by:DawG25
ID: 13429386
Thanks for the help, I forgot about the key having to be the firs column.  The formula works great in a computed field, but I would like it to be editable.  Can this be done in a regular text field?
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13433474
Not neccessarily the first column, but the first SORTED column!

So if the comboboxes are changed, you want the @DbLookup to do the job AND be able to change the result?

What happens if the comboboxes get changed after you have edited the title? Overwrite?

It can be done. Haven't decided to do that in @Formula, Lotusscript of Javascript though.... Thinking of JS and some help of two additional hidden fields: one to act as the computed field (i.e. the current field) and one to act as a flag to keep track of the last change: combobox of title. The translation event of the editable field could then determine wether or not to copy the original title.

Do realize that the edited title won't update the document holding the key!
0
 
LVL 3

Expert Comment

by:sravikiran
ID: 13435124
Create a computed hidden field ("Title") that has the @dblookup formula. This field holds the title of the document.

Now, create an editable field "TitleDisp". In the onLoad even of the form, write the following Javascript

document.forms[0].TitleDisp.value = document.forms[0].Title.value

Note:Make sure to use the field names in the Javascript the same case as you have for the field name.
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13436868
That would reset the edited TitleDisp to the original value if the document is opened again....
0
 
LVL 13

Accepted Solution

by:
CRAK earned 800 total points
ID: 13437231
I have constructed a situation here to accomplish what you (probably) need.
I have used different fields though:

Combo1 and Combo2 are my comboboxes.
DefaultTitle and EditFlag as hidden editable text fields (make sure that html is generated for these field too, or javascript will fail!)
myTitle as the editable field that should either inherit the default title, or keep the edited one.

Both combobox fields should hold this javascript code in the onChange event:
   document.forms[0].EditFlag.value='0';

note: Javascript is case sensitive; EditFlag is one of the fieldnames.

DefaultTitle has following formula (both Default and Translation). It's the formula that you tested/approved earlier:
   Ttl:=@DbLookup(""; ""; "(TitleByKey)"; Combo1 + Combo2; 2);
   @If(
      @IsError(Ttl);
      "n.a.";
      Ttl)

note: (TitleByKey) is my viewname.

EditFlag has a default value "0"

myTitle has a default and translation formula:
   @If(
      EditFlag = "0";
      DefaultTitle;
      myTitle)

It also has following javascript in the onKeyDown event:
   document.forms[0].EditFlag.value='1';

I bet this'll do the job perfectly (if you have all fieldnames correct).
0
 
LVL 3

Expert Comment

by:sravikiran
ID: 13445006
Yep, that will reset the value when you open the document. If you want to show the title in an editable field and have the user change it and keep the changes you change the code in my posting to :

if (document.forms[0].TitleDisp.value =="") {
document.forms[0].TitleDisp.value = document.forms[0].Title.value ;
}

This makes sure that if the user has modified the value (or accepted the default value), don't replace it.
0
 
LVL 13

Expert Comment

by:CRAK
ID: 13447604
That'll get you in trouble if users change their mind (they always have these nasty habits...) and prefer the original title again.
My code handles that too!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question