Can someone help convert this one line of Formula to Lotus Script please?

I used to use this piece of code to perform a lookup which worked flawlessly when I used it in the Formula language. However, our code has moved to Lotus Script and this line of code in the Lotus Script isn’t working correctly.

MailQuotaFormula = Evaluate (|@DbLookup(“”:“”; @Subset(@DbName;1) : “names.nsf”; “($MailFileQuotaView)”; @Name([CN]; @V3UserName) ; 2)|)

MailQuotaResults = MailQuotaFormula(0)

I had declared MailQuotaFormula as a Variant and MailQuotaResults as a String. The code works great for a short while (say, a week) and then all of a sudden one more users get an error “Variant does not contain a container”. Since I couldn’t get the error to go away, I just pulled the code from the templates to stop performing the lookups.

So basically, its just a simple lookup in the Domino Directory, in the ($MailFileQuotaView) view, search for a name and give me the value next to it. There surely has to be a more reliable way to do this and I’d be very grateful if someone could take just one moment to help me out.

Subject: Re: Formula

Is your @DbLookup failing for this particular user?

I’d suggest adding an @If(@IsError… statement if you want to do something specific if it fails, otherwise add the [FailSilent] parameter if you just want to avoid errors.

Regards

Paul

Subject: Alternate Method

You can also get the QUOTA information from the DB Properties in LotusScript… If you can get the database in question into a Database Object then you can use the DbObject.SizeQuota and DbObject.SizeWarning so it should just be a matter of putting a Database script into the User’s Mail file on the POSTOPEN even that does something like this

Dim ThisSession as New NotesSession

Dim ThisDB as NotesDatabase

Dim ThisQuota as Long

Set ThisDB = ThisSession.CurrentDatabase

ThisQuota = ThisDB.SizeQuota

… Do something with the quota …

Steve

Subject: Need the lookup only

Well its basically just a lookup in the NAB for a field. We don’t use the typical quota features because they don’t provide adequate enforcement, so we use an alternative method which this code helps with. I did find the solution here:

http://www-10.lotus.com/ldd/nd8forum.nsf/DateAllThreadedWeb/ec1816f4e21b3db08525761c00253813?OpenDocument

Thanks so much for your help!

Subject: Did you search the help for the error message?

I"Variant does not contain a container" simply means that you’re accessing a variant as an array…but it’s not an array. This happens when the DBLookup doesn’t return anything.

You have to perform an IsArray test on MailQuotaFormula and handle it properly according to what it is.

You should try to avoid using Evaluate in your code, and always rewrite the code fully in LotusScript. In this case, you just get a handle on the view and execute a getdocumentbykey

’ keep Dim statements on top of code and in alphabetic order.

’ variables appear in the debugger in the order in which they’re declared.

Dim mail as NotesDatabase

Dim mailquota as variant

Dim names as NotesDatabase

Dim quotaview as NotesView

Dim resultdoc as NotesDocument

Dim thisns as new NotesSession

Call mail.OpenMail

Set names = thisns.GetDatabase( mail.Server , “names.nsf” , False ) ’ assumes mail db is on the server you want to use.

’ OR

Set names = thisns.GetDatabase( thisns.CurrentDatabase.Server , “names.nsf” , False ) 'assumes the current db is on the server you want to use.

If names Is Nothing Then

Msgbox( “Directory not found” )

Exit Sub

End If

Set quotaview = names.GetView( “($MailFileQuotaView)” )

Set resultdoc = quotaview.GetDocumentByKey( thisns.CommonUserName , True )

mailquota = resultdoc.ColumnValues( 1 )

It’s more code, but now you can debug it and you can also check for problems during processing, such as checking names for a value of Nothing.

Dunno if this works…was off the top of my head, but it should be close.