Create a new resource in ALM/QC using OTA

Create a new resource in ALM/QC using the Open Test Architecture API. First a new resource is created then file is attached to that resource. The below sub accepts 4 parameters. This sub uses a TDConnection object. Create it before using the below code.

Parameter Info -

1) resourceFolderId – Folder Id in which the resource has to be created.
Test Resource Folder Id

2) fileType – Type of resource
File Type

3) fileName – Name of file
4) fileParentFolderPath – Folder path in which file is present on local machine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Sub CreateNewResource(resourceFolderId As Integer, fileType As String, fileName As String, fileParentFolderPath As String)
 
    On Error GoTo Errhandler:
 
    '--- Represents a file or folder stored in the Quality Center repository
    Dim resource As QCResource
    '--- Represents a QC resource folder.
    Dim resourceFolder As QCResourceFolder
    '--- Services for managing QC resources.
    Dim resourceFactory As QCResourceFactory
    '--- Services for managing QC resource folders.
    Dim resourceFolderFactory As QCResourceFolderFactory
    '--- Services to manage resource storage.
    Dim testResourceStorage As IResourceStorage
    Dim resourceItem
    Dim resourceFound As Boolean
 
    ' ***TDConn is TDConnection class object.Create this object before using this function.
    Set resourceFolderFactory = TDConn.QCResourceFolderFactory
    Set resourceFolder = resourceFolderFactory.Item(resourceFolderId)
    Set resourceFactory = resourceFolder.QCResourceFactory
    Set currResourceList = resourceFactory.NewList("")
 
    For ItemCount = 1 To currResourceList.Count
        currItem = currResourceList.Item(ItemCount).Name
        If UCase(currItem) = UCase(fileName) Then
            Set resourceItem = currResourceList.Item(ItemCount)
            resourceFound = True
            Exit For
        End If
    Next
 
   If Not resourceFound Then
        '--- Create a resource
        Set resourceItem = resourceFactory.AddItem(fileName)
        resourceItem.ResourceType = fileType
        resourceItem.fileName = fileName
        resourceItem.Post
 
        '--- Check if the resources added successfully
        Set currResourceList = resourceFactory.NewList("")
        For ItemCount = 1 To currResourceList.Count
            currItem = currResourceList.Item(ItemCount).Name
            If UCase(currItem) = UCase(fileName) Then
                resourceFound = True
                Exit For
            End If
        Next
 
        If resourceFound Then
            '--- Attach the file to resource
            resourceItem.vC.CheckOut ""
            Set testResourceStorage = resourceItem
            testResourceStorage.UploadResource fileParentFolderPath, False
            resourceItem.vC.CheckIn "Automated check-in by utility" & Now
        Else
             oFile.WriteLine ("Recently added new resource not found on ALM.Try again later.")
             Exit Sub
        End If
    Else
        resourceItem.vC.CheckOut ""
        Set testResourceStorage = resourceItem
        testResourceStorage.UploadResource fileParentFolderPath, False
        resourceItem.vC.CheckIn "Automated check-in by utility" & Now
    End If
 
    Set resourceFolderFactory = Nothing
    Set resourceFolder = Nothing
    Set resourceFactory = Nothing
    Set currResourceList = Nothing
 
    Exit Sub
 
Errhandler:
   MsgBox("Error Executing - `CreateNewResource`  ; Error Uploading file " & fileName)
   Exit Sub
End Sub
  • Joy

    Very Nice Blog.
    Its useful for me.

  • Aizert Eduard

    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