0

I get a Runtime error:

"-2147219913 (80040637) Automation error
"you do not have the required permissions to execute this action"

while trying to upload a file to Test case in QC using VBA.

Set QCConnection = CreateObject("TDApiOle80.TDConnection")
QCConnection.InitConnectionEx QCurl
QCConnection.Login qcID, qcPWD
QCConnection.Connect qcDomain, qcProject

Dim runName, sCount, TestSetParent, TestSetCount, ActualMessage, attachFactory

nPath = "Test Lab Path"
Set TSetFact = QCConnection.TestSetFactory
Set tsTreeMgr = QCConnection.TestSetTreeManager
Set tsFolder = tsTreeMgr.NodeByPath(nPath)
Set tslist = tsFolder.FindTestSets("Test Set Name")

i = 1
j = 1
Set theTestSet = tslist.Item(i)
For Each testsetfound In tslist
    Set tsFolder = testsetfound.TestSetFolder
    Set TSTestFactory = testsetfound.TSTestFactory
    Set tsTestList = TSTestFactory.NewList("")
    k = 1
    For Each tstItem In tsTestList
        If Not IsEmpty(tstItem) Then
            runName = tstItem.RunFactory.UniqueRunName
            Set RunF = tstItem.RunFactory
            Set theRun = RunF.AddItem(runName)
            theRun.Name = runName
            theRun.Status = "Passed"
            theRun.CopyDesignSteps
            theRun.Post
        End If
        Set runStepF = theRun.StepFactory
        Set aTestStepArray = runStepF.NewList("")
        step_cnt = aTestStepArray.Count
        For j = 1 To step_cnt ' Loop through steps and update in qc
            Set runStep = aTestStepArray.Item(j)
            step_QC = runStep.Name
            runStep.Field("ST_ACTUAL") = runStep.Field("ST_EXPECTED")
            runStep.Status = "Passed"
            runStep.Post
            k = k + 1
        Next

        Set fso = CreateObject("Scripting.FileSystemObject")
        Set Inputfolder = fso.GetFolder("FilePath")
        Set Infiles = Inputfolder.Files
        For Each InFile In Infiles
            Set attachFactory = theRun.Attachments
            Set attachment = attachFactory.AddItem(Null)
            attachment.Filename = "Filename"
            attachment.Type = 1     
            attachment.Post
            theRun.Refresh
            theRun.Post
            Set attachFactory = Nothing
        Next
    Next
Next

Error happens in the line

         attachment.Post

What might be the required permission?

Community
  • 1
  • 1
Raja
  • 57
  • 1
  • 8
  • What type is `attachment`, and why is [tag:excel] relevant? – Mathieu Guindon Nov 20 '19 at 20:49
  • attachment is a .docx file. Removed the excel tag – Raja Nov 20 '19 at 21:05
  • That was not the question. `attachment` is some object variable, and your code isn't showing any declaration for any of the variables involved, so we're left guessing what's what. Presumably we're not looking at an `Outlook.MailItem`? What type/class is the `Post` method defined in? Is it a custom VBA class? Have you verified your permissions? "you to not have have the required permissions" looks pretty clearly like a permission error, not a code error. – Mathieu Guindon Nov 20 '19 at 21:08
  • yes, I am getting the runtime error for Permissions only. but I am not sure what sort of permission is required. – Raja Nov 20 '19 at 21:36
  • Usually that implies read/write permissions for your Windows login user, to whatever `"FilePath"` stands for. – Mathieu Guindon Nov 20 '19 at 21:38
  • Then again that's just a stab in the dark, because I've no idea what class type an `attachment` is and what its `Post` method does. Is it provided by the QC object model? Does QC have a user permission system? – Mathieu Guindon Nov 20 '19 at 21:48
  • @MathieuGuindon : Thanks for your inputs. Filepath is a folder in my local machine. It is just the POST method for File Attach that is having this issue. I am able to execute test cases through the tool, but unable to attach my test results – Raja Nov 20 '19 at 21:49
  • Ok, see, the file being local *is* relevant information that belongs in the post. Now since the file being local rules out file/path permissions, we're left with `attachment.Post` being the problem. So, one last time, [edit] your post to indicate what class type `attachment` is and more context around what its `Post` method is supposed to be doing. Most people viewing your question are not familiar with [tag:qc], and associate attachments with Outlook emails. Verify that your user is allowed to add attachments... does it work if you do it manually, without scripting? – Mathieu Guindon Nov 20 '19 at 21:54
  • I just uploaded my entire code. Yes, I am able to upload attachments manually in QC version 12.5 – Raja Nov 20 '19 at 22:10

1 Answers1

0

Here is the fix I made to upload attachments to Quality Center.

Set attachFactory = theRun.Attachments
Set attachment = attachFactory.AddItem(Null)
attachment.Filename = "Filename"
attachment.Type = 1     
attachment.Save       ' <------changed the method to save instead of post for upload in QC
Community
  • 1
  • 1
Raja
  • 57
  • 1
  • 8