Instr - @contains

Hello,

I have a field (dialog box) that users can select mulitple values. I usually use @contains to verify if the value contains one of the strings. I need to use lotus script and i tried to use the following code found on this forum but its not working.

If Instr(doc.Requesttype(0), “Change Name”) > 0 Then

Call SendNotification(session, db, doc)

End If

Any help is truly and greatly appreciated. Thanks in advance.

Subject: Instr - @contains

Did you do a debug and check what the value of doc.Requesttype(0)? Remember it has to match perfectly, and it’s case sensitive too. I used Instr a lot and it works fine.

Subject: Instr - @contains

What exactly is “not working”? Is the code blowing up or is it just not doing what you wanted?

Subject: RE: Instr - @contains

Hi; Thanks for the quick response.

Its actually not doing what i want, if the user selects “Change Name” and “Update Information” - that’s fine.

But when they click the button, the code should verify if the field is equal to or contains “Change Name” it then calls Send notification → which then emails.

Subject: RE: Instr - @contains

It may be that it’s a “case-sensitivity” problem. If leaving out the last parameter, Instr defaults to a case-sensitive mode. Try this and see if this helps:

If Instr(1, doc.Requesttype(0), “Change Name”, 5) > 0 Then

I normally specify “5” for case insensitive. If that still doesn’t work, try the debug, as was suggested to verify that Requesttype does indeed contain “Change Name”.

Hope that helps.

Subject: RE: Instr - @contains

I just re-read your initial post and realized what the problem might actually be. You say the users can select multiple values from the dialogbox (Requesttype). But your Instr line only checks the 1st value of Requesttype, which would work if the user only selected “Change Name”.

You can keep the base code but put it in a loop that iterates through all values in Requesttype.

Hope that helps.

Subject: RE: Instr - @contains

Hi;

Sorry, Im not too familiar with Script, How would I create a loop that will iterate through all values in Requesttype?

Subject: RE: Instr - @contains

you don’t have to loop thru all the values, you can simply have.

dim item as notesItem

set item = doc.getFirstItem( “your field”)

if item.contains( “your value”) = true then

send your mail

end if

john

Subject: RE: Instr - @contains

Thank you to both, I tried both and it works! Very Very much appreciated :slight_smile: Have a nice day!

Subject: RE: Instr - @contains

This is one possibility:

Dim i As Integer, ub As Integer

ub = Ubound(doc.Requesttype)

For i = 0 To ub

	If Instr(doc.Requesttype(i), "Change Name") > 0 Then

		Call SendNotification(session, db, doc)

Exit For

	End If

Next

Hope that helps.

Subject: Instr - @contains

There is a parameter missing on Instr - the first parameter should tell it where to start looking

Instr(1, doc.RequestType(0), “Change name”)