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.