Home > Domino Tips > Developer > Other > Developer tool: Read/set document fields from view
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

Developer tool: Read/set document fields from view


Andre Guirard
06.12.2004
Rating: -3.83- (out of 5)


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


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.

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.


Submit a Tip




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


RELATED CONTENT
Other
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Using the XMLHTTP object for integration with Domino or any RDBMS back end
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
AddParameter to a NotesXSLTransFormer
Using DXL (Domino XML) to review/modify documents

Lotus Notes Domino Formula Language
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
Add a program doc to compact Lotus Notes databases automatically
Top 10 Lotus Notes Domino programming and development tips of 2007
Retrieve Lotus Notes names from a nested group using @DBLookup

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 enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and 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