Author not authorized to attach file to new document

I am trying to create a new Notes document using an id with Author access. I create the document on the backend, populate some fields, lookup a Word document in another document in the database, detach it and reattach it to the new Notes document. It is upon an attempt to attach the Word document that the code fails and I get the message “You are not authorized to perform that operation.”

Things I have already checked:

  • The code runs fine if the user has Editor access. It only fails if the user has Author access.

  • The new document is populated with the user’s canonical name in an authors field (verified by observing the data type - 1076 - of the NotesItem) and the IsAuthors property of the authors field.

  • Saving the document prior to attempting to attach the file makes no difference.

  • The file is definitely detached to the hard drive.

Here is the code (exluding declarations and supporting routines). Any ideas why it would fail for Author access? Anybody else experience this?

Sub Initialize

%REM

SUMMARY

  • this agent gets a word or excel template from the database settings, enters data into the file according to document type being created, creates a new document in the database and attaches the file, and opens the new document in the user interface

CALLS

  • DatabaseSpecificRoutines script library (just contains constants for field values)

  • GetSettingByCompKey routine in SettingRoutines script library (used to get Notes document containing Word file and other database settings)

  • GetBillData (gets data from parent document)

  • DetachWordTemplateFromSetting (saves attachment held in setting document to temp directory)

  • DetachXLTemplateFromSetting (saves attachment held in setting document to temp directory)

  • EnterWordData (enters data into detached Word file)

  • EnterXLData (enters data into detached Excel file)

CALLED BY

  • New Action button(s) on DocHeader subform

SPECIAL INSTRUCTIONS

  • shared agent

  • runs from agent list on all selected documents

  • security level 1 (do not allow restricted operations)

%END REM

strSubjErr = "Error creating document"

On Error Goto tagErrorBatch



Set session = New NotesSession

Set workspace = New NotesUIWorkspace

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set docBill = dc.GetFirstDocument

strUserCommon = session.CommonUserName

strToday = Format$(Now, "mm/dd/yyyy")



strDocType = session.GetEnvironmentString(ENV_DOC_TYPE)

Call session.SetEnvironmentVar(ENV_DOC_TYPE, "")



'ensure doc type retrieved

If Len(strDocType) = 0 Then

	

	Error G_ERR_NUM_NO_DOCTYPE, G_ERR_MSG_NO_DOCTYPE

	

Else

	

	

	'get data from bill

	Call GetBillData

	

	Print G_MSG_GET_ATTACH

	

	'get handle to setting document

	Set docSet = GetSettingByCompKey(VAL_SET_CATEGORY_TEMPLATE, strDocType)

	

	'check if setting returned

	If docSet Is Nothing Then

		

		Error G_ERR_NUM_CANNOT_ATTACH, G_ERR_MSG_CANNOT_ATTACH

		

	Else

		

		Print G_MSG_ATTACH

		

		If strDocType = G_VAL_DOC_TYPE_ADM Then

			

			'detach attached spreadsheet from setting

			Call DetachXLTemplateFromSetting

			

			'set values on spreadsheet

			Call EnterXLData

			

		Else

			

			'detach attached document from setting

			Call DetachWordTemplateFromSetting

		

			'set values on word document

			Call EnterWordData

			

		End If

		

		'create notes document and attach document

		Set docNew = New NotesDocument(db)

		Call docNew.MakeResponse(docBill)

		Call docNew.ReplaceItemValue("Form", G_FRM_DOC)

		Call docNew.ReplaceItemValue(G_FLD_DOC_TYPE, strDocType)

		Call docNew.ReplaceItemValue(G_FLD_CREATED_TIME, Now)

		Set item = New NotesItem(docNew, G_FLD_DOC_AUTHOR, session.UserName, AUTHORS)

		'Call docNew.ReplaceItemValue(G_FLD_DOC_AUTHOR, session.UserName)

		Call docNew.ReplaceItemValue(G_FLD_LAST_MOD_TIME, Now)

		Set item = Nothing

		Set item = New NotesItem(docNew, G_FLD_LAST_MOD_NAME, session.UserName, NAMES)

		Set item = Nothing

		'Call docNew.ReplaceItemValue(G_FLD_LAST_MOD_NAME, session.UserName)

		

		'enter data from bill

		Call docNew.ReplaceItemValue(G_FLD_SESSION_YEAR, Cint(strSessionYr))

		Call docNew.ReplaceItemValue(G_FLD_BILL_NUM, strBillNum)

		Call docNew.ReplaceItemValue(G_FLD_TITLE, strBillTitle)

		Call docNew.ReplaceItemValue(G_FLD_BILL_STATUS_CODE, strBillStatus)

		Call docNew.ReplaceItemValue(G_FLD_BILL_VERSION, strBillVer)

		Call docNew.ReplaceItemValue(G_FLD_TAX_TYPE, strTaxType)

		Call docNew.ReplaceItemValue(G_FLD_EA_AUTHOR, strEACanon)

		Call docNew.ComputeWithForm(True, False)

		

		'set computed when composed fields on workflow subform

		strStatusDefault = GetSetAttribByCompKey(VAL_SET_CATEGORY_KEYWORD, VAL_STATUS_DEFAULT_LKUP_NAME, 

VAL_STATUS_DEFAULT_LKUP_COL)

		Call docNew.ReplaceItemValue(FLD_STATUS, strStatusDefault)			

		

		'attach document

		Set rtitem = New NotesRichTextItem(docNew, G_FLD_ATTACH)

		Call rtitem.EmbedObject(EMBED_ATTACHMENT, "", strFilePath)	'<<<< CODE FAILS HERE

		Delete rtitem

		

		'delete file from hard drive

		Kill strFilePath

		

		'open new document in user interface

		Set uidoc = workspace.EditDocument(True, docNew)

		

		Print G_MSG_COMPLETE

		

	End If	

	'end check if setting returned

	

End If

'end check for doc type

tagOut:

Exit Sub

tagErrorBatch:

Print ""

strErr = Cstr(Err)

strError = Error$ & " in " & Lsi_info(2) & " on line " & Cstr(Erl)

Call ProcessUIErrorNotes(strErr, strError)

Call ProcessErrorNotes(docNew, strErr, strError, strSubjErr)

Resume tagOut

End Sub

Thank you for any assistance you provide.

Subject: Author not authorized to attach file to new document

Hi,

i dont see any error in the code nor do i know this error.

Just a few ideas which you could try and post the results:

  1. Try to remove the line “Call docNew.ComputeWithForm(True, False)” as it might change the

field type of your authors-field and see if it works.

  1. Try to “remember” the unique id of the document. Save it. Clear the variable (“Delete docNew”) and

then get the document again using “DB.GetDocumentByUNID”. Does it help ?

  1. Save the document without adding the attachment. Does this give the error too ??

Bye

Hynek

Subject: RE: Author not authorized to attach file to new document

Hynek,

Thank you so very much for responding to my post and confirming that I am not insane - although I may be headed there soon. :wink:

I have tried all of your suggestions (and a few ideas of my own), but none of them has aleviated the error. If I have a save command in the script prior to the attempt to attach the document, the document is saved without error, the authors property of the document is set to the Author’s canonical name, and the authors field I inserted is indeed READ/WRITE ACCESS NAMES. The Author can edit the saved document.

I am no longer thinking that this is an issue with my code but am instead leaning towards an agent security issue or a problem with my login. On a couple of occasions (not all, of course) while testing, I was prompted to enter my location while stepping through the code.

I greatly appreciate any advice you or others may provide. Have a great day!

Subject: RE: Author not authorized to attach file to new document

Hi,

one more idea:

Check if the agent is allowed to perform restricted operations.

(Open the agen in the designer, open the agent properties, goto the last tab)

This setting is new in R6 and i often forget to set it. Maybe it is necessary for

the action “use a file from the filesystem”

Good luck

Hynek

Subject: RE: Author not authorized to attach file to new document

Hynek,

Once again, thank you for your help. I have been playing with these settings, although I didn’t go the full-blown “Allow restricted operations with full administration rights” route yet. Still no luck.

I found this in the technotes (pasting since I get tired of broken links) when searching on the error number I got.


Number: 166347

Problem

You have designed an application that attaches and detaches files using LotusScript. Your users who have Author access should be able to attach and detach all files, but when they attempt to attach or detach certain Word Pro 96 files, the following error occurs:

        "4067 - Couldn't attach file" 

The Word Pro 96 files are small, less than 10K bytes in size. Users who have Editor or higher access have no problems attaching or detaching the Word Pro 96 files.

Solution

This issue has been reported to Lotus Quality Engineering.

Supporting Information

Related Documents

LotusScript Cannot Create an Attachment For a User Who Does Not Have Rights to Create Documents

Document #: 166571


While my attachments are not Word Pro, they are very small.

I will look into trying to run this agent on the server (so it will have my rights) or perhaps the run on behalf of options. I’ll post back with any news.

Once again thank you for all of your help (and for the luck as I seem to need it).

Subject: Solution: Author not authorized to attach file to new document

I was able to get around this limitation by breaking my original code into 2 agents and calling the second agent from the first using the RunOnServer method of NotesAgent. I had to sacrifice the functionality that actually launched the word or excel file and entered data into it, but I could have probably left that in if the software was installed on the server.

For the interested (or horribly bored), here is the code.

Agent agtCreateDoc1:

Sub Initialize

%REM

SUMMARY

  • this agent gets a word or excel template from the database settings, creates a new document in the database and attaches the file, and opens the new document in the user interface

CALLS

  • DatabaseSepcificRoutines (script library containing field name and other constants)

  • GetSettingByCompKey routine in SettingRoutines script library

SPECIAL INSTRUCTIONS

  • shared agent

  • runs from agent list on all selected documents

  • security level 2 (do allow restricted operations)

%END REM

strSubjErr = "Error creating document"

On Error Goto tagErrorBatch



Set session = New NotesSession

Set workspace = New NotesUIWorkspace

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

strUserCommon = session.CommonUserName

strToday = Format$(Now, "mm/dd/yyyy")



strDocType = session.GetEnvironmentString(ENV_DOC_TYPE)

Call session.SetEnvironmentVar(ENV_DOC_TYPE, "")



'ensure doc type retrieved

If Len(strDocType) = 0 Then

	

	Error G_ERR_NUM_NO_DOCTYPE, G_ERR_MSG_NO_DOCTYPE

	

Else

	

	'check if bill selected

	'If docBill.Form(0) = FRM_BILL Then

	

	Set docNew = New NotesDocument(db)

	Call docNew.MakeResponse(doc)

	Call docNew.ReplaceItemValue("Form", G_FRM_DOC)

	Call docNew.ReplaceItemValue(G_FLD_DOC_TYPE, strDocType)

	Call docNew.ReplaceItemValue(G_FLD_CREATED_TIME, Now)

	Set item = New NotesItem(docNew, G_FLD_DOC_AUTHOR, session.UserName, AUTHORS)

	Delete item

	Call docNew.ReplaceItemValue(G_FLD_LAST_MOD_TIME, Now)

	Set item = New NotesItem(docNew, G_FLD_LAST_MOD_NAME, session.UserName, NAMES)

	Delete item

	

	'enter data from bill

	Call docNew.ReplaceItemValue(G_FLD_SESSION_YEAR, doc.GetItemValue(G_FLD_SESSION_YEAR)(0))

	Call docNew.ReplaceItemValue(G_FLD_BILL_NUM, doc.GetItemValue(G_FLD_BILL_NUM)(0))

	Call docNew.ReplaceItemValue(G_FLD_TITLE, doc.GetItemValue(G_FLD_TITLE)(0))

	Call docNew.ReplaceItemValue(G_FLD_BILL_STATUS_CODE, doc.GetItemValue(G_FLD_BILL_STATUS_CODE)(0))

	Call docNew.ReplaceItemValue(G_FLD_BILL_VERSION, doc.GetItemValue(G_FLD_BILL_VERSION)(0))

	Call docNew.ReplaceItemValue(G_FLD_TAX_TYPE, doc.GetItemValue(G_FLD_TAX_TYPE)(0))

	Set item = New NotesItem(docNew, G_FLD_EA_AUTHOR, doc.GetItemValue(G_FLD_EA_AUTHOR)(0), AUTHORS)

	Delete item

	

	'set computed when composed fields on workflow subform

	strStatusDefault = GetSetAttribByCompKey(VAL_SET_CATEGORY_KEYWORD, VAL_STATUS_DEFAULT_LKUP_NAME, VAL_STATUS_DEFAULT_LKUP_COL)

	Call docNew.ReplaceItemValue(FLD_STATUS, strStatusDefault)

	

	Call docNew.Save(True, False)

	strNoteID = docNew.NoteID

	

	

	Dim agent As NotesAgent

	Set agent = db.GetAgent("agtCreateDoc2")

	Call agent.RunOnServer(strNoteID)

	

	Delete docNew

	Set docNew = db.GetDocumentByID(strNoteID)

	Call workspace.EditDocument(True, docNew)

	

	'Else

	

		'Error ERR_NUM_NOT_BILL, ERR_MSG_NOT_BILL

	

	'End If

	'end check if bill selected

	

End If

'end check for doc type

tagOut:

Exit Sub

tagErrorBatch:

Print ""

strErr = Cstr(Err)

strError = Error$ & " in " & Lsi_info(2) & " on line " & Cstr(Erl)

Call ProcessUIErrorNotes(strErr, strError)

Call ProcessErrorNotes(doc, strErr, strError, strSubjErr)

Resume tagOut

End Sub 'agtCreateDoc1

Agent agtCreateDoc2:

Sub Initialize

%REM

SUMMARY

  • this agent gets a word or excel template from the database settings, creates a new document in the database and attaches the file, and opens the new document in the user interface

CALLS

  • DatabaseSpecificRoutines script library

  • GetSettingByCompKey routine in SettingRoutines script library

  • DetachWordTemplateFromSetting

  • DetachXLTemplateFromSetting

SPECIAL INSTRUCTIONS

  • shared agent

  • runs from Action menu selection (Traget: None)

  • security level 3 (restricted operations with full administration rights)

%END REM

strSubjErr = "Error creating document"

On Error Goto tagErrorBatch



Set session = New NotesSession

Set db = session.CurrentDatabase

Set agent = session.CurrentAgent

Set doc = db.GetDocumentByID(agent.ParameterDocID)

strDocType = doc.GetItemValue(G_FLD_DOC_TYPE)(0)

strUserCommon = session.CommonUserName

strToday = Format$(Now, "mm/dd/yyyy")



Print G_MSG_GET_ATTACH



'get handle to setting document

Set docSet = GetSettingByCompKey(VAL_SET_CATEGORY_TEMPLATE, strDocType)



'check if setting returned

If docSet Is Nothing Then

	

	Error G_ERR_NUM_CANNOT_ATTACH, G_ERR_MSG_CANNOT_ATTACH

	

Else

	

	Print G_MSG_ATTACH

	

	If strDocType = G_VAL_DOC_TYPE_ADM Then

		

		'detach attached spreadsheet from setting

		Call DetachXLTemplateFromSetting

		

	Else

		

		'detach attached document from setting

		Call DetachWordTemplateFromSetting

		

	End If

	

	'attach document

	Set rtitem = New NotesRichTextItem(doc, G_FLD_ATTACH)

	Call rtitem.EmbedObject(EMBED_ATTACHMENT, "", strFilePath)

	

	Call doc.Save(True, False)

	

	Delete rtitem

	

	'delete file from hard drive

	Kill strFilePath

	

End If	

'end check if setting returned

tagOut:

Exit Sub

tagErrorBatch:

Print ""

strErr = Cstr(Err)

strError = Error$ & " in " & Lsi_info(2) & " on line " & Cstr(Erl)

Print strErr & " " & strError

Resume tagOut

End Sub 'agtCreateDoc2

Of course I still have some more work to do to see if I can bump these access levels down a bit.

Once again thanks to Hynek as well as others (esp. Julie K.) who have unwittingly helped through their previous posts.

Hope this helps out others as well. Have a great day!

Subject: Follow-Up: Don’t use LZ1 Compression (Author not authorized to attach file to new document)

I sent my database into Lotus for some assistance. They stated that it was horribly corrupt and that running utilities (fixup et al) would not repair it. The only way to fix it was to recreate from scratch every design element in the database. So I did that (a few times, actually), but the problem would always resurface. Since some late user changes to the requirements made my workaround of using two agents unusable, I ended up giving everybody editor access and “rolling my own” security.

However, upon working on a different database, the same problem resurfaced. I have found that if I disabled the database property “Use LZ1 compression for attachments” authors could create new documents and embed attachments without error.

I hope this helps out somebody.

Subject: RE: Follow-Up: Don’t use LZ1 Compression (Author not authorized to attach file to new document)

Hello Lynn,

thank you so much for your tip regarding the LZ1 Compression. It saved my weekend!!! I had exactly the same problem and had already spend several hours in it before I read you tip.

Thanks again

Subject: RE: Follow-Up: Don’t use LZ1 Compression (Author not authorized to attach file to new document)

Thanks for your tip.

Is this considered a BUG? I mean my users were fine attaching files to a RTF field for months before 1 (and only 1 user) raised a problem.

Thanks for the tip though, saved me from stress.

JJ

Subject: Unless… you are on Notes 7???

I am using Notes 7.0 and got the same problem. I am not using any compression (perhaps it is the default for 7).

To recreate the problem:

  • Create a new database on a server

  • Add a */YourOrganisation entry to the ACL as a Mixed Group, and give it Author access with no additional ACL ticks

  • Create a form with an author field and a body (rich text) field on it

  • Create a document using the form and your own id with full Manager access

  • Add some full canonical username to the author field e.g. “CN=Joe Soap/O=YourOrganisation” (don’t worry if it reformats it to take away the canonical format - it is saved in canonical format)

  • Save the document

  • Switch to that user’s id

  • Open the document and save it as many times as you want - no problem

  • Now attach a file to the body field. At this point, I get a “you are not authorized to perform this operation” error.

Any help or ideas would be appreciated, thank you.

Subject: Similar Issue: Author not authorized to attach file to new document

I am pretty sure this is either an ECL issue or some strange ACL issue involving the agent. I have similar code acting as a mailer. It creates a new document in the Mail.Box db of the active server, populates a few fields, gets an Excel worksheet (previously saved to disk), and embeds it. the document is then “mailed” by saving it to the mail.box db.

the code works fine in R5, and is broken when the R6 client is used. it breaks exactly when the embed takes place. it works when I use a developer or admin account. attempts to change the agent privileges (from most restrictive “1” to least “3” in the agent properties box), resolved nothing.

clearly, all things being unchanged, the code should run, so I would suspect a bug. IRIS?

here is my code, from object creation to embedding:

Set o = createobject(“Excel.Application”)

With o

__.workbooks.open wrk

__Sleep 1 ’ delay allows larger workbooks to load

__loadData .workbooks(1)

__formatData .workbooks(1)

__.workbooks(1).save

__.workbooks(1).close

End With

’ create and route mail message

With s.getdatabase(b.server, “mail.box”)

__With .createdocument

____.from = “LIHI Financial Reports”

____.posteddate = Now

____.sendto = email

____.recipients = email

____.subject = title+Format$(Now, " YYYY MMM DD at HH:MM")

____.createrichtextitem(“body”).embedobject EMBED_ATTACHMENT, “”, wrk

____.save True, True

__End With

End With

Msgbox “Report '”+title+“’ has been sent to “+Chr(13)+Chr(10)+email+”.”, 64, “Report Sent”

Subject: RE: Similar Issue: Author not authorized to attach file to new document

I have the same problem.Users have author access and when I try to embed the object yhe message was “Notes error - You are not authorazied…”.

My code is in a Lotus script library, not in a agent and with R5 works fine.

With editor access all works fine.

I tried also to change the ECL without any result.

Any suggestion ?

Subject: RE: Similar Issue: Author not authorized to attach file to new document

I had the same issue: 6.5.4FP2 server/6.5.3 client - A group with Author access and no other ACL options (except the implicit Read Public Documents). Docs could be updated/saved with text in a rich text field, but attaching files resulted in “You are not authorized…” error when the user attempted to save the doc. I enabled “Write Public Documents” for the group and it resolved the issue. Not sure why.