Manage Learn to apply best practices and optimize your operations.

Smart icon to set field value/type, version 2

Version one of this tip, "Set field value/type via smart icon" by Janet Rogers, was submitted on Sept. 4, 2001.

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.

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.

Dig Deeper on Lotus Notes Domino Formula Language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close