Manage Learn to apply best practices and optimize your operations.

Developer tool: Read/set document fields from view

This handy tip makes testing and debugging applications easier by letting you reassign a field without editing the document.

View member feedback to this tip.

When testing and debugging applications, it's handy to be able to reassign a field without editing the document (since the form might prevent you from making the change you want, or might change other fields you didn't want to).

You can do this with a smarticon (or in ND6, toolbar icon) containing a statement such as

FIELD Status := "Draft"

However, it's a pain to create a new smarticon for each field you want to set. Here's a formula for a smarticon that shows you a list of the fields in the highlighted document and lets you choose one, then prompts you for a new value. The type of the field is preserved (for instance, if it had a date value before, the value you enter will be converted to a date, not stored as a string.)

Even if you didn't want to change the field value, this smarticon lets you see what fields are in the document and what their values are. You can also do this with the Document Properties dialog, but the smarticon does two things Document Properties can't: it works even in databases with hidden designs; and, with the ND6 version of the formula, you can see the values of all the fields by just scrolling thru the choice list -- you don't have to click on each individual field.

Document Properties is still better for seeing the full value of rich text fields, field flags and datatypes, etcetera, but if you're not sure which field contains the value you're looking for, this is a quicker way to find it.

Code: REM "Formula for R5";
choices := @DocFields;
fieldName := @Prompt([OkCancelEditCombo]; 
"Field Name"; "Enter Field
Name."; ""; choices);
oldValue := @GetField(fieldname);

newValue := @Explode(@Prompt([OkCancelEdit]; 
"New Field Value"; "Please
enter new value (use ";" for multivalues -- 
don't put space after ;)."; @Implode
(@Text(oldvalue); ";")); ";"); 

adjValue :=
   @If(@IsNumber(oldValue); 
@TextToNumber(newValue);
   @IsTime(oldValue); 
@TextToTime(newValue);
   newValue);

@If(!@IsError(adjValue);
   @SetField(fieldName ; adjValue); 
@Prompt([YesNo]; "Change field value";
 "New value not of same type as 
old value. Set field to text?");
   @SetField(fieldName ; newValue);
   ""
)


REM "Formula for ND6";
choices := @DocFields;
fullChoices := @Transform(choices; "x"; x + 
" = " + @Implode(@Text(@GetField
x)); ";"));
fieldName := @Prompt([OkCancelEditCombo]; 
"Field Name"; "Enter Field 
Name."; ""; FullChoices);
fieldName := @Left(fieldName; " = ");
oldValue := @GetField(fieldname);

newValue := @Explode(@Prompt([OkCancelEdit]; 
"New Field Value"; "Please
enter new value (use ";" for multivalues -- 
don't put space after ;)."; @Implode
(@Text(oldvalue); ";")); ";");

adjValue :=
   @If(@IsNumber(oldValue); 
@TextToNumber(newValue);
   @IsTime(oldValue); @TextToTime(newValue);
   newValue);

@If(!@IsError(adjValue);
   @SetField(fieldName ; adjValue);
@Prompt([YesNo]; "Change field value"; 
"New value not of same type as 
old value. Set field to text?");
   @SetField(fieldName ; newValue);
   ""
)

MEMBER FEEDBACK TO THIS TIP

@GetField is not available in R5, so I offer a workaround:

REM "Formula for R5"; choices :=
 @DocFields; fieldName := @Prompt
([OKCANCELEDITCOMBO]; "Field Name"; 
"Enter Field Name."; ""; choices);
oldValue := @Abstract([TextOnly] ; 200; "";
 Fieldname ); newValue := @Explode
(@Prompt([OKCANCELEDIT]; 
"New Field Value"; "Please enter new value (use
";" for multivalues -- don't put space after ;).
"; @Implode (@Text
(oldvalue); ";")); ";"); adjValue := 
@If(@IsNumber(oldValue); @TextToNumber
(newValue); @IsTime(oldValue); 
@TextToTime(newValue); newValue); 
@If(!@IsError
(adjValue); @SetField(fieldName ; adjValue); 
@Prompt([YESNO]; "Change field 
value"; "New value not of same type as old value. 
Set field to text?"); 
@SetField(fieldName ; newValue); "" )

—Joseph L.

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

That is a very slick development tool/tip. I tried using it and ran into a problem using it in R5.0X

In Andre's code, he uses:

oldValue := @GetField(fieldname);
But there is no @getField function in R5.0X, so I've attempted to correct this by using:
FIELD DUID := @text(@DocumentUniqueID);
oldValue := @GetDocField (DUID;fieldname);
Which now complies.

But I'm still not out of woods yet. It's still not "working as expected," since I'm not getting the old value.

Upon investigation, I'm getting a "@SetDocField and @GetDocField cannot access the document currently being computed."

I don't currently have a workaround for this.

—Ian I.

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

My bad -- I've been using ND6 for so long that I forgot this function wasn't available in R5. Sorry!

I guess there's not a way to have it display the old value in R5; nor can it detect the old type of the field and set the new value to the same type. Here's a new formula for R5 that does as much as is possible in that version. To use this formula, type # before a number value -- [ before a date value, or ~ before a string. @DEL can be used to delete an item (I hope!). If you don't use a prefix character, the formula will assume you mean a string. Use ; as multi-value separator. So for instance, type #14;9 to set the item to a number list containing the values 14 and 9. If you type ~14;9 or 14;9 you will set the field to a text list containing the string values "14" and "9".

_choices := @DocFields; 
_fieldName := @Prompt([OkCancelEditCombo];
 "Field Name"; "Select Field 
Name."; ""; _choices); 
_newValue := @Prompt([OkCancelEdit]; 
"New Value - " + _fieldName; "New 
value (use leading # for number fields, 
[ for dates, ~ for strings. 
Separate multivalues with ; (no space) )."; ""); 
_firstchar := @Left(_newValue; 1); 
_fixNew := @Explode(@If(firstChar = 
"~":"#":"["; _newValue; @RightBack
(_newValue; 1)); ";"; 1); 
_adjValue := 
   @If(_firstChar = "#"; @TextToNumber(_fixNew); 
   _firstChar = "["; @TextToTime(_fixNew); 
   _fixNew); 
@If(@IsError(_adjValue); 
   @Prompt([Ok]; "Change field value"; 
"Conversion error!"); 
_newValue = "@DEL"; 
   @SetField(_fieldName ; @Unavailable); 
   @SetField(_fieldName ; _adjValue) 
) 
Ian, please e-mail feedback whether this works for you --thanks. I notice the change doesn't always display in the document properties dialog right away (FYI).

Andre Guirard

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Andre Guirard. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

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