Requires a Valid ADT argument... How can I fix this?

Hello,

I am seeing “Requires a valid ADT argument” on this line of code:

Call newdoc.CopyItem( item, “RegMark” )

Does anyone know how I can fix this?

I will display all the code below, but first, this is what I’m trying to do.

I have a document which can list between 1 and 5 car registrations depending on how many cars you have. For each car registration, when this document is approved, it should create another document for each car, with the registration field already filled in.

This code is in an agent. Here is the code:

Initialize Section:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim ws As New NotesUIWorkspace

Dim view As NotesView

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim user As String

Dim strFieldName As String



Set db=session.CurrentDatabase

Set uidoc = ws.CurrentDocument

Set doc=uidoc.Document



uidoc.Reload

uidoc.Refresh



If ( Trim(doc.RegMark(0)) <> "") Then

	Call CreateNew (db, doc, doc.RegMark(0))

End If



For a = 1 To 4 

	strFieldName = "RegMark_" + a

	If ( Trim(doc.GetItemValue( strFieldName)(0) ) <> "") Then

		Call CreateNew (db, doc, strFieldName)

	End If

Next

End Sub

CreateNew SubRoutine

Sub CreateNew (db As NotesDatabase, doc As NotesDocument, regMarkFieldName As String)

Dim newdoc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim AutoCheckDate As New NotesDateTime("")

Dim AutoNextCheckDate As New NotesDateTime("")

Dim item As NotesItem



'create new document

Set newdoc=New NotesDocument(db)

Set rtitem =New NotesRichTextItem(newdoc,"Body")

Set AutoCheckDate = New NotesDateTime("Today")

Set AutoNextCheckDate = New NotesDateTime("Today")



Call AutoCheckDate.AdjustMonth(-1)



Call doc.Save(False,False)



newdoc.Form = "Vehicle Check Report"

newdoc.Name = doc.Name

newdoc.Tel = doc.Tel

newdoc.Dep = doc.Dep

newdoc.JobTitle = doc.JobTitle

'newdoc.RegMark = doc.GetItemValue( regMarkFieldName )

Call doc.Save(False,False)

Set item =doc.GetFirstItem (regMarkFieldName)

Call newdoc.CopyItem( item, "RegMark" )

newdoc.CompanyHireCar = doc.CompanyHireCar

newdoc.OnshoreOffshore = doc.OnshoreOffshore

newdoc.Status = "Current"

newdoc.RetToggle = "Yes"

Call newdoc.ReplaceItemValue("VehicleCheckDate", AutoCheckDate)

Call newdoc.ReplaceItemValue("NextVehicleCheckDate", AutoNextCheckDate)	

Call newdoc.Save(True, True)



'create new mail

newdoc.Form="Memo"

newdoc.Subject="Crawley Business Drivers DB - Vehicle Check Form enclosed for " & doc.FullName(0)



Call rtitem.AppendText("Please find below the Vehicle Check Form for you to complete on a regular basis.")

Call rtitem.AddNewLine(1)

Call rtitem.AppendText("Please contact Facilities if you require further information.")

Call rtitem.AddNewLine(2)

Call rtitem.AppendText("Please follow the link to view the document ->>  ")

Call rtitem.AppendDocLink(newdoc,db.Title)

Call rtitem.AddNewLine(2)

Call rtitem.AppendText("Thank you...")

Call rtitem.AddNewLine(2)

flag=newdoc.ComputeWithForm(False,False)

Call newdoc.Send (False, doc.GetItemValue("FullName" ))

End Sub

I’d really appreciate any help with this as I’m completely stuck.

Thanks in advance,

Hayley.

Subject: Requires a Valid ADT argument… How can I fix this?

Hayley,

In your initialize you have:

For a = 1 To 4

	strFieldName = "RegMark_" + a

	If ( Trim(doc.GetItemValue( strFieldName)(0) ) <> "") Then

		Call CreateNew (db, doc, strFieldName)

	End If

Next

I think that should be the following in order for getitemvalue to work correctly:

For a = 1 To 4

	strFieldName = "RegMark_" + a

	If ( Trim(doc.GetItemValue( strFieldName)) <> "") Then

		Call CreateNew (db, doc, strFieldName)

	End If

Next

Or if that doesn’t work then try:

For a = 1 To 4

	strFieldName = "RegMark_" + a

	If (Trim(doc.GetItemValue(cstr(strFieldName)(0))) <> "") Then

		Call CreateNew (db, doc, strFieldName)

	End If

Next

Ultimately I don’t think you need the (0) because you have strFieldName declared as a string so it’s the contents of the variable that are in play. If you had it declared as an array or variant then you would need to provide the array position to get the string you want.

Shawn

Subject: Requires a Valid ADT argument… How can I fix this?

Looking at your coding your missing a key line which may or may not be the error issue

Set item =doc.GetFirstItem (regMarkFieldName)

should be

if doc.HasItem(regMarkFieldName) then

  Set item =doc.GetFirstItem (regMarkFieldName)

Else

  'Blah blah field missing handler......

end if

That may or may not be your issue

Subject: Requires a Valid ADT argument… How can I fix this?

Hayley,

What is your agent trigger? Are you attempting to run this agent in a document in read mode? I’ve only seen the Valid ADT argument error when I attempt to run an agent/action on a document in read mode when I am calling UI objects. Most of the UI objects do not work in read mode.

Brandt

Subject: RE: Requires a Valid ADT argument… How can I fix this?

Hello Brandt,

The manager is selecting the “Approval” button, this does take the document into read mode to set a few fields etc… but then it triggers a couple of agents to set-up a few more documents automatically. This one which I’m having trouble with is one of them. Regardless if a RegMark field is filled in, a new form has to be created, but if RegMark, RegMark_1, RegMark_2, RegMark_3 or RegMark_4 have a value, then that value is copied over to the new document which is created for each of them. So if only RegMark is filled in, then only one document is created, but if RegMark_1 and RegMark_2 is filled in, then 2 documents are created.

Does that make sense?

Thanks for your help.

Hayley.

Subject: RE: Requires a Valid ADT argument… How can I fix this?

One last thing…

In your createNew() sub you save the doc you pass in but don’t change it. Did you intend to save your newdoc?

Call doc.Save(False,False)

Try to recompile the lotusscript and see if that gets rid of your ADT error.

Cheers,

Shawn

Subject: RE: Requires a Valid ADT argument… How can I fix this?

Also,

You can not execute either of these in Read-Only mode.

uidoc.Reload

uidoc.Refresh

You will need to pull them (They aren’t doing anything for you anyway)

or put this above them

uidoc.editMode = True

Shawn

Subject: Requires a Valid ADT argument… How can I fix this?

The “Requires a valid ADT Argument” is coming from the Call newdoc.CopyItem( item, “RegMark” ).

I’ve noticed that item is not assigned a value, even though regMarkFieldName has a value. I don’t know how to fix this. Can you help? I’ve not got much lotusscript experience. I have commented out the save and uidoc.refresh etc… in the agent, but that doesn’t make a difference.

Thanks,

Hayley.

Subject: RE: Requires a Valid ADT argument… How can I fix this?

Hi Hayley,

The fact that there is no handle to the item is causing you the ADT error.

What is the value of the regMarkFieldName string? I notice that when you call the function…

If ( Trim(doc.RegMark(0)) <> “”) Then

Call CreateNew (db, doc, doc.RegMark(0))

End If

… you are passing in the value of the field, not the field name. I think you need to change this part of the code to-

If ( Trim(doc.RegMark(0)) <> “”) Then

Call CreateNew (db, doc, “RegMark”)

End If

Try this anyway. If it still doesn’t work, you need to concentrate on getting a notes item object into your item variable.

Andrew.

Subject: RE: Requires a Valid ADT argument… How can I fix this?

Hi Andrew,

You’ve fixed it for me :wink: Thank you so much.

Hayley.

Subject: RE: Requires a Valid ADT argument… How can I fix this?

Why do you go thru the hastle? If is it an ordinary field, just use this:

if trim$(doc.RegMark(0)) <> “” then

newdoc.RegMark = trim$(doc.RegMark(0))

instead of —> Call newdoc.CopyItem( item, “RegMark” )

Also I think when you use ‘CopyItem’, it should be:

Call newdoc.CopyItem( item, “” ) to copy the itemvalue into “RegMark” field on new document. Otherwise it should be… Call newdoc.CopyItem( item, “RegMark$” ), to copy the itemvalue into “RegMark$” field on new document, instead of RegMark which is the original field on existing document from where you want to copy. Hence may be the reason for that Error message as you are using the same field name in new doc. Read help.