lotus notes, search data that equal to textbox

2019-08-25 08:49发布

问题:

I don't understand why my code is not allowed.

@If(@DbLookup("":"nocache";@DbName;"GPA";1)="GPnum";@Failure(@Command([FileSave])&@Command([CloseWindow]));@Success)`

Please help me. Thank you.

回答1:

@If(@DbLookup("":"nocache";@DbName;"GPA";1)="GPnum"

your code should have 1 more parameter.

from help

@DbLookup( class : cache ; server : database ; view ; key ; fieldName ; keywords )

So you have "GPA" as view and then you need to specify Key and field/column you wish to return. Also for DbLookup I would recommend you to use [FAILSILENT] as keywords, in this case you will not need to check result for @IsError

However probably you just need to use @DbColumn instead of @DbLookup.

as I understood you need to verify if some value exists in database/view, try this code:

@If(@DbColumn("":"NoCache";@DbName;"GPA";1)="GPnum"; @Failure(@Command([FileSave]) : @Command([CloseWindow])); @Success)

or

@If(@DbLookup("":"NoCache";@DbName;"GPA"; "GPnum"; 1; [FAILSILENT])<>""; @Failure(@Command([FileSave]) : @Command([CloseWindow])); @Success)


回答2:

Edit: I add a code for button action that save the current doc (see author comment below)
The editable field in which the user enters the value we check is called GPnum. A view "GPA" is sorted by its first col an display GPnum value.

t:=@DbLookup("":"nocache";@DbName;"GPA"; GPnum ; 1 ; [FailSilent] );
@If(@IsError(t) ; @Prompt([Ok]; "DB has a problem:";@Text(t)) ;
  t = "" ; @Do(@Command([FileSave]);@Command([CloseWindow])) ;
  @Prompt([Ok] ; "unable to save" ; "The key already exists") )

original response

t:=@DbLookup("":"nocache";@DbName;"GPA"; @ThisValue ; 1 );
@If(@IsError(t) ; @Failure("DB has a problem:"+@Text(t)) ; t =  "" ; @Success ; @Failure("The key already exists") )

If you use @failure/@success you MUST be in an editable field in a form (validation). As I understand you check that your value does not ALREADY exists. so:

first add @thisValue as the key you search in the DBLOOKUP, as told above DBLOOKUP could return an error thus check @isError(t)
second failure just BLOCK the validation of the form, I never tried (an it doesn't make sense) to make it save the form

Hope it helps