Custom Workflow Code to Add folders & Files in resources not working

  • Questions
  • Custom Workflow Code to Add folders & Files in resources not working
Question ID: 104448
2
0

worfkow scripts to add folders & files under test resources using QCResource, QCResourceFactory, QCResourceFolder & QCResourceFolderFactory objects but none seems to be working. Using the AddItem method throws an error and nothing gets created.

Sample of Code

Set rFolderFactory = TDConnection.QCResourceFolderFactory.root.QCResourceFolderFactory

set newFolder = rFolderFactory.AddItem(Null)

newFolder.Name = "Archive Test Results"
newFolder.parentId = 1
newFolder.Post

‘Create Resource
Set rResourceFactory = QCResourceFactory
Set newResource = rResourceFactory.AddItem(Null)

newResource.Name = "Results_Path"
newResource.ParentId = newFolder.Id
newResource.ResourceType = "Test Resource"
newResource.Post

Set newResource = Nothing
Set newFolder = Nothing
Set rResourceFactory = Nothing

Set rFolderFactory = Nothing

Marked as spam
Posted by (Questions: 22, Answers: 1)
Asked on January 23, 2012 11:14 am
18 views
Answers (2)
5
Private answer

When adding an item using the QCResourceFactory the QCResourceFactory needs to be created from an existing QCResourceFolder and not directly from the TDConnection. Even though the Object is being created as a virtual object that you will place in a non root folder you still need to provide a path to a non root folder. You can then specify any non root folder that you want to put the object in. So your code should look like this.

'Create Resource Folder
Set rFolderFactory = TDConnection.QCResourceFolderFactory.root.QCResourceFolderFactory
set newFolder = rFolderFactory.AddItem(Null)

newFolder.Name = ''Archive Test Results''
newFolder.parentId = 1
newFolder.Post

'Create Resource
Set rResourceFactory = newFolder.QCResourceFactory
Set newResource = rResourceFactory.AddItem(Null)

newResource.Name = ''Results_Path''
newResource.ParentId = newFolder.Id
newResource.ResourceType = ''Test Resource''
newResource.Post

Set newResource = Nothing
Set newFolder = Nothing
Set rResourceFactory = Nothing

Set rFolderFactory = Nothing

Basically just take the newFolder Object you created First and set your rResourceFactory object equal to newFolder.QCResourceFactory then the rest of the code should work fine.

Marked as spam
Posted by (Questions: 1, Answers: 69)
Answered on January 23, 2012 11:25 am
0
Private answer

Hello Everybody,

I need to make a code for HP UFT that is moving a Test Resource from one Folder to Other. Please Help if anybody has Suggestions. Thx

Marked as spam
Posted by (Questions: 1, Answers: 2)
Answered on September 15, 2017 8:26 am