Home > Domino Tips > Developer > Smart icon to set field value/type, version 2
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

FORMULA

Smart icon to set field value/type, version 2


Dave Lehman
09.02.2003
Rating: -4.61- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

Editor's Note: Version one of this tip, Set field value/type via smart icon by Janet Rogers, was submitted on Sept. 4, 2001 and won the SearchDomino.com Tips Contest that month. The following tip is another version of Janet's.

This formula can be pasted into a custom smart icon (tool button) in the Notes client. It allows you to arbitrarily set the value of any field on the document. Using the formula, you can easily change field values during testing without having to write an agent or go through all steps of a workflow, etc.

This improved version uses the existing value and type of the field, if it already exists.

As in the original, when used in a smart icon button, this formula allows you to set both field value and/or data type of any Notes document on the fly. It covers all data types and allows changes to single or multiple value fields.

Code

View member feedback to this tip.

Editor's Note: Version one of this tip, Set field value/type via smart icon by Janet Rogers, was submitted on Sept. 4, 2001 and won the SearchDomino.com Tips Contest that month. The following tip is another version of Janet's.

This formula can be pasted into a custom smart icon (tool button) in the Notes client. It allows you to arbitrarily set the value of any field on the document. Using the formula, you can easily change field values during testing without having to write an agent or go through all steps of a workflow, etc.

This improved version uses the existing value and type of the field, if it already exists.

As in the original, when used in a smart icon button, this formula allows you to set both field value and/or data type of any Notes document on the fly. It covers all data types and allows changes to single or multiple value fields.

REM {SmartIcon formula for arbitrary alteration 
of a field};
REM { v1.1 - if field exists, uses default value and 
default field type in @Prompt dialogs 
[Dave Lehman, 2003-09-02]};

unid:= @Text(@DocumentUniqueID);

theField := @Prompt([OkCancelList]; 
"Change Field"; "Select Field"; ""; "":@DocFields);

currValueTemp:= @If( @IsAvailable(theField); 
@GetDocField(unid; theField); "errorTemp" );
currValue:= @If( @IsError(currValueTemp); 
"errorValue"; @Text(currValueTemp) );
theValue := @Prompt([OkCancelEdit]; 
"Change Field"; "New Value: use 
semicolon separator for lists."; currValue);

currType:= @If( @IsNumber(currValueTemp); 
"Number"; @IsTime(currValueTemp); "Time"; "Text" );
theType := @Prompt([OkCancelList]; 
"Change Field"; 
"Data Type"; currType; "Text" : "Time" : "Number" : "Text List" : "Number List" : "Time List"); @If( theType = "Time"; @SetField(theField; @TextToTime(theValue)); theType = "Number"; @SetField(thefield; @TextToNumber(theValue)); theType = "Text List"; @SetField(theField; @Trim(@Explode(theValue;";"))); theType = "Number List"; @SetField(theField; @TextToNumber (@Explode(@Trim(@ReplaceSubstring (theValue;" ";""));";"))); theType = "Time List"; @SetField(theField; @TextToTime (@Explode(theValue;";"))); @SetField(theField; @Text(theValue)) )

MEMBER FEEDBACK TO THIS TIP

The browser, of course, wordwrapped the text for the formula, so I had to edit the text to get the tip to work. However, after that I get an "errorValue" in the default value of the field. I put some debug code in and discovered that the @GetDocField is returning an error:

"@SetDocField and @GetDocField cannot access the document currently being computed."

-- Don C.

*************************************************

I pasted your code into a smart icon and it doesn't work.

The "Change Field" prompt box has "errorTemp" in it so I assume something is amiss in the "currValueTemp" field or possibly in the "theField" field.

Anyone else ask you about this?

-- Bob M.

*************************************************

I liked the tip. I dropped the code into a smart icon and had no problems. The only modification I made was to add some code to be able to delete a field. I added one line to include the delete option in the field type prompt, as shown below:

theType := @Prompt([OkCancelList]; "Change Field"; "Data Type";
currType; "Text" : "Time" : "Number" : "Text List" : "Number List" : "Time
List":"Delete Field");
Then, I added the line below to the @If that handles the field type:
theType = "Delete Field";
@SetField(theField; @DeleteField);
-- Dave P.

*************************************************

This is a good refinement for this tool. However, it can be further enhanced by changing the first prompt from:

theField :=
@Prompt([OkCancelList]; "Change Field"; "Select Field"; ""; "":@DocFields)',
to 'theField := @Prompt([OkCancelEditCombo]; "Change Field"; "Select Field";
""; "":@DocFields)
Doing this allows you to add new fields to a form, a task that is sometimes necessary during the early stages of development.

-- Dominic H.

*************************************************

I tried this code out and it seems to work just fine for me. I'm not sure why those others are having problems, but maybe they could post their code and we could help them find out what's wrong.

-- SearchDomino.com member

*************************************************

I also have had problems. For the record, I am running R5.0.10 on Win95. As a check, I have inserted three extra @prompt lines. The first two confirm that the field has been correctly selected and that the correct UNID is in place. The third returns "errorvalue," indicating that the field is not available. Attempts to modify the field directly without querying its availability were similarly unsuccessful.

unid:= @Text(@DocumentUniqueID); 
theField := @Prompt([OKCANCELLIST]; "Change Field"; "Select Field"; ""; "":@DocFields); 

@Prompt([OK];"field";theField ) ; 
@Prompt([OK];"unid";unid); 

currValueTemp:= @If( @IsAvailable(theField);   @GetDocField(unid; theField);"errorValue"); 

@Prompt([OK];"currval";currValueTemp); 
-- Richard H.

*************************************************

I have been using this code since it was posted and as an inexperienced developer, I use it DAILY! It has worked for most things that I want to do and I have NEVER had to adjust it at all. I'm going to try to add the first two member feedback posts from here. BUT I'll make sure to keep my original one! Thanks for the biggest time-saver I have found!

-- Pamela D.

*************************************************

The code works in ND6 but in Notes version 5 you cannot retrieve the value of an existing field -- it always returns the value "errorTemp" due to an error mentioned in another comment: "@SetDocField and @GetDocField cannot access the document currently being computed."

Beats me why!!!!

-- Richard K.

*************************************************

I would like this tip very much if it would work. But in my version of Notes (5.0.10, German), it does not work. I had to change the brackets in the REM lines in the beginning to quotation marks. Now I get the same error as Don C. in the first comment. Do you use Notes 6 to have @GetDocField working on the current document?

-- Stephan S.

*************************************************

Thinking about the R5/R6 difference, it seemed a good idea to try:

FIELD theField := @Prompt([OKCANCELLIST]; "Change Field"; "Select Field"; ""; 
"":@DocFields);
etc.

Unfortunately this made no difference, nor did a line declaring

FIELD theField := theField.
at the beginning.

The good news is that on my system at any rate, provided that the document is open for editing, the unmodified code inserts the new value into the desired field, even though the old value is not retrieved. This works for computed as well as editable fields. The bad news is that although the field type changes to the requested type, this change is lost when the document is saved.

So the limited functionality available under R5 can be obtained with a greatly cut-down version:

theField := @Prompt([OKCANCELLIST]; "Change Field"; "Select Field"; ""; "":@DocFields); 
theValue := @Prompt([OKCANCELEDIT]; "Change Field"; "New Value: use semicolon 
separator for lists."; currValue); @setfield(theField;theValue)
If a text list is inserted into a text field, then the field type changes to text list for that document only. The change persists, even if a single value is subsequently inserted.

-- Richard H.

*************************************************

I have not problems running this from a view. I do have problems running this when the document is open in R5.

-- Ralph B.


Do you have comments of your own? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Smart Icons
Easy way to count members of a group
SmartIcon code to display any open database's ReplicaID
SmartIcon shortcut to server
Special action ... SmartIcon @Formula for day-to-day tasks
Quick admin function in Notes client
Get the size of a user's mail database while in the Domino Directory
Quick import-export smart icons
Set field value/type via smart icon
SmartIcon to open a mailfile from NAB
Add mail file icon from NAB

Formula
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Provide rich-text formatting via the Profile document and Formula
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Formula language button manages Deny Access list searches
Retrieve Lotus Notes names from a nested group using @DBLookup
Create a computed Lotus Notes field to list Personal Address Book names
Show multiple Lotus Notes document fields in a single view column
How to send a document as a link in a Lotus Notes email

Lotus Notes Domino Formula Language
View hidden fields on Lotus Notes/Domino forms
Case-insensitive @Unique version combines fields on Lotus Notes forms
Do I use Formula or LotusScript to include a doclink to a Notes view?
Top 10 Lotus Notes/Domino coding and development tips of 2008
Provide rich-text formatting via the Profile document and Formula
Top 10 Formula language tips
Using Formula language code to sort Lotus Notes messages by subject
How to create dynamic JavaScript in Notes Domino without formulas
Stop response documents from showing in a Lotus Notes form
Formula language button manages Deny Access list searches

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts