开发者

Update computed fields without validating

开发者 https://www.devze.com 2023-04-11 03:25 出处:网络
I have a form with a field ItemNumber that has a validation forumla that ens开发者_JAVA技巧ures a value is entered.

I have a form with a field ItemNumber that has a validation forumla that ens开发者_JAVA技巧ures 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?


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.


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消