1
votes

I have a form with a field ItemNumber that has a validation forumla that ensures a value is entered.

In lotusscript i create a new document with that form, then depending on the value of a different computed field ItemProductFamilyType (computed based on a field of another doc) i might want to populate ItemNumber.

The issue i have is that if i look at the value of ItemProductFamilyType it's blank, because it's not yet been computed. It'll only have a value once a field is updated, then it's the document refreshed/re-computed.

I'm trying to use ComputeWithForm for this (with the raiseError parameter being a 1 or 0), however because of validation formulas on other fields it's not letting me.

So, how can i get computed fields to update their value without checking/erroring on validation formulas?

3
Be careful with ComputeWithForm (From the help) "Validates a document by executing the default value, translation, and validation formulas, if any are defined in the document form." But what you try should work. What do you mean with "not letting me", what is the error?Jasper Duizendstra
Just to clarify, the help does not mention any computed fields, I always understood it was not guaranteed they will compute.Jasper Duizendstra
It doesn't update the computed field.George Duckett
Hmm, that's true, in my experience they did however maybe i'm just relying on a side-effect. In which case my question becomes, how can i update a computed field in lotusscript?George Duckett

3 Answers

2
votes

Try adding a validation control field. So, add a field called "runValidation". It's computed for display, as it's only required for UI form events handling. It's formula is straight forward

@ThisValue or runValidation

In the QueryRecalc event or whenever you want to set the value for ItemProductFamilyType set it to "1".

Sub Queryrecalc(Source As Notesuidocument, Continue As Variant)
    On Error Goto errHandle
    Dim doc As notesDocument
    Set doc = source.Document
    ' go populate your fields like ItemProductFamilyType
    doc.runValidation = "1"
    Exit Sub
errHandle:
    Messagebox Lsi_info(2) + " : " + Str(Err) + " - " + Error(Err) + ", at line " + Str(Erl)    
    Exit Sub 
End Sub

The same idea works in the translation formula of ItemProductFamilyType

Field runValidation := "1";
@thisValue;

In the validation formula for ItemNumber include the "runValidation" field to manage when the field should validate.

@if(runValidation="1";@if(@trim(@ThisValue)="";@Failure("Enter value");@Success);@Success)

You should now be able safely call a Source.Refresh method without inadvertently triggering validation rules until the data is ready.

2
votes

I'm not sure if there's a Lotus Notes-specific workaround for this, but one trick that would work in any system is to have another test in your validation formulas. Instead of saying just @If(FieldName != ""; @Failure; @Success), add another condition that you can control like @If(DoValidation = "Yes" & FieldName != ""; @Failure; @Success). Then you can control validation by controlling the value of the DoValidation item.

I often add @IsDocBeingSaved to the condition so that validation only fires when you are saving the document:

@If(@IsDocBeingSaved & FieldName != ""; @Failure; @Success)
1
votes

Another thought, given the potential that the ComputeWithForm method is unreliable: Why not check the value in the other document using LotusScript? In fact, you could call that same code from the QueryRecalc event and update the ItemProductFamilyType item, sparing you the need to duplicate code.