Markus
Markus

Reputation: 291

Type mismatch in method RunStkCoerceVal in Lotusscript

First of all I want so say, that I'm a very beginner in developing a Domino Application. So please consider this fact when answering my possibly dumb question.

I have the following problem:
When I execute the following code, it runs into the 1st MsgBox which shows up just normal. But it does not run into the 2nd MsgBox! Instead I get the following error message:

Type mismatch in method RunStkCoerceVal in Lotusscript agent STRING found Null expected.

Here is the code:

    Dim session As NotesSession
    Dim db As NotesDatabase
    Dim ws As New NotesUIWorkspace
    Dim thisDoc As notesUIDocument
    Dim docSMBPrivateProfile As notesDocument
    Dim test As Variant

    Set session = New NotesSession
    Set db = session.CurrentDatabase
    Set thisDoc = ws.CurrentDocument
    Set docSMBPrivateProfile = db.GetDocumentByUNID(thisDoc.FieldGetText("SMB_PRIVATE_PROFILE_DOCUMENT_ID"))

    Msgbox("This message will appear")
    Set test = docSMBPrivateProfile.FieldGetText("DOCUMENT_ID_TEST")
    Msgbox("This message won't appear")

Please note that the call thisDoc.FieldGetText("SMB_PRIVATE_PROFILE_DOCUMENT_ID") works normal just as expected.

I set the data type of test to Variant in order to avoid type mismatch problems. In fact I expect a String.

The only topic I found about this problem is found here: http://www.secure-eserver.com/?p=3431 But I'm not able to make head or tail of it.

Can you please provide me any help?

Upvotes: 1

Views: 2327

Answers (3)

Michael Ruhnau
Michael Ruhnau

Reputation: 1399

Since docSMBPrivateProfile is a NotesDocument object. The method FieldGetText does not exist in the NotesDocument class. You can get the field value by using this code:

dim myStringVar as string
myStringVar = docSMBPrivateProfile.DOCUMENT_ID_TEST(0)
...

As you already said you use variant only due to that error. Therefor I suggest to use a string with the above mentioned code. It should not generate a type mismatch error.

It seems you got a bit confused with the two documents in your code. You could use FieldGetText for the second document "thisDoc" as it is a NotesUIDocument object. The even better method for accessing the field would be (as suggested by Panu)

docSMBPrivateProfile.GetItemValue("DOCUMENT_ID_TEST")(0)

Upvotes: 4

Panu Haaramo
Panu Haaramo

Reputation: 2932

docSMBPrivateProfile is based on NotesDocument class which does not have FieldGetText method. Use test = docSMBPrivateProfile.GetItemValue("DOCUMENT_ID_TEST")(0) instead.

Upvotes: 2

Simon O'Doherty
Simon O'Doherty

Reputation: 9359

Go to Tools->Debug LotusScript menu option. Then run the code. Step through it to see what exactly is failing in the line in question.

In fact I expect a String.

Assuming the field exists, it will return an array, not a string. So you would need to do something like the following (again assuming it is only one string in the field).

Set test = docSMBPrivateProfile.FieldGetText("DOCUMENT_ID_TEST") (0)

Upvotes: 0

Related Questions