HP ALM - download a resource under a specific folder in the Test Resource module - alm

We are using ALM 12. We have multiple folders in our Test Resources module, and some of the resources stored in these folders have the same name as in other folders. I am able to download a resource using the name, but can't figure out how to get a resource under a specific folder. Anyone know how to download a resource specifying the folder to download it from?
e.g
Folder1
mysheet.xls
Folder2
mysheet.xls
I want to download Folder2\mysheet.xls and not Folder1\mysheet.xls

You could download the resource by resource id rather than resource name.
Below is VBS sample (with OTA API) for your reference:
Option Explicit
Dim tdc, cust, resource
set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx "http://YourALMServer:Port/qcbin"
tdc.Login "username", "password"
tdc.Connect "domainName", "projectName"
# 1001 is the resource id which you want to download.
set resource = tdc.QCResourceFactory.Item("1001")
# "C:\\tmp\\" is the local path where you want to place the downloaded resource
resource.DownloadResource "C:\\tmp\\", TRUE
tdc.Disconnect
tdc.Logout
tdc.ReleaseConnection

Option Explicit
Dim objCon, cust, resource
set objCon= CreateObject("TDApiOle80.TDConnection")
objCon.InitConnectionEx "http://YourALMServer:Port/qcbin"
objCon.Login "username", "password"
objCon.Connect "domainName", "projectName"
Set oResourceFolder = objCon.QCResourceFolderFactory
Set oFilter = oResourceFolder.Filter
oFilter.Filter("RFO_NAME") ="abc" \\ abc is your folder name
Set oList = oFilter.NewList()
set oChild = oList.item(1).QCResourceFactory.NewList("")
''assuming that there is only 1 folder with name "abc" in Test Resources section
For i =1 to oChild.count Step 1
oChild.item(i).DownloadResource "c:\\a", TRUE
''c:\\a is the location where we need to safe the resource
next
set objCon = Nothing

Related

Delete directory content using Azure Automation DSC

I am using Azure Automation DSC to deploy some basic configurations on my Azure VMs. However, I am struggling to delete recursively all the content of C:/Temp directory and leave the directory as an empty folder.
I am using the following code:
$temp_dir = "C:\temp\"
File "Clean Temp Folder" # Delete $temp_dir Directory
{
Ensure = "Absent"
Type = "Directory"
Recurse = $true
DestinationPath = $temp_dir
Force = $true
}
As soon as I assign node configuration to the VM, C:/Temp/ folder gets deleted completely, but if I recreate it manually afterwards it won't be deleted on the next DSC run even though the Force parameter is set to true.
Any suggestions are very welcome!
I would recommend to go with Script resource or else if you want to go with File resource only then try something as shown below.
$temp_dir = "C:\temp\"
File "Clean Temp Folder" # Delete $temp_dir Directory
{
Ensure = "Absent"
Type = "Directory"
Recurse = $true
DestinationPath = $temp_dir
Force = $true
}
$temp_dir = "C:\temp\"
File "Create empty Temp Folder" # Create empty $temp_dir Directory
{
Ensure = "Present"
Type = "Directory"
DestinationPath = $temp_dir
Force = $true
}
The issue was on the Azure side. While I was registering nodes in DSC, the configuration mode was set to ApplyAndMonitor.
The bad thing is that the setting was not visible for the already registered node, but after re-registering the issue was solved.
Screenshot

VBA Sharepoint Check In File after Upload

Been using this code for a while to upload a file to SharePoint and noticed the other day that when the file is uploaded, it is checked out to myself automatically and have to go into SharePoint and manually check-in so that others can view the file. Any way to modify or add to my code below to auto check-in a file after it uploads? Totally stumped and any help would be greatly appreciated.
Sub SharePointUpload()
Dim WSN
Dim spAdd
Set WSN = CreateObject("WScript.Network")
spAdd = "https://mysharepoint/test"
WSN.mapnetworkdrive "N:", spAdd
ActiveWorkbook.Save
Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object
' Where you will enter Sharepoint location path
SharepointAddress = "\\mysharepoint\test"
' Where you will enter the local file path
LocalAddress = "C:\data\sample_file.xlsm"
Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
Else: MsgBox "File does not exist!"
End If
Set objNet = Nothing
Set FS = Nothing
WSN.removenetworkdrive "N:"
End Sub
I had the same issue with our SharePoint Document library even with option Require Check Out switched off - some documents (Word, Excel) were uploaded as Checked Out automatically (green arrow mark) whereas others were in fact Checked In from upload. Moreover when I wanted to Check In manually such documents, I got error message about missing mandatory field, although there was no field in the library set as mandatory.
The reason in my case was the field Title. This field is presented in library as default text field and it is also presented in Office files. I noticed that for Office files with empty field Title the document is automatically Checked Out during upload. When uploaded document contained some text in Title property, no Check Out was set. I also tried to use workflow to change the Title and then Check Out file (after creation), but it was not working - initial Check In was required to start the workflow. Manual change of document properties works but that's too tedious...
The first programmatic option to handle this issue could be to fill Title property of uploaded document when empty (i.e. add file name or any other text). Should work well with many languages. Example with Python:
from docx import Document
path = 'D:/myfile.docx'
document = Document(path)
document_property = document.core_properties
if not document_property.title:
document_property.title = 'Everything is Awesome'
document.save(path)
In VBA Title should accessible via Wb.BuiltinDocumentProperties("Title").
Another successful option for me was to find column Title in Columns of Document library and rename it to something else (I used Titlex as new name), then try to upload new document with empty Title - this time there was no automatic Check Out for the uploaded document. Then I could set the Titlex back to Title without returning the issue.

How to edit an embedded PDF in Excel via VBA and AVDoc?

I want to edit a pdf file attached as an object to my Excel doc with VBA.
Background: Since I don't want to share both files in a .zip or else and there is no network drive everybody has granted access to, I need a "foolproof" solution.
The pdf file contains a form (mandatory) and will be filled with information from this Excel doc. As mentioned, I already had a solution with the pdf file stored on a network drive.
Dim file, new_name As String
Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")
'Open new PDF file
'Use local path
file = "C:\Users\992\Desktop\example.pdf"
new_name = "New_PDF_12092019"
If AvDoc.Open(Datei, Name) Then
AcroApp.Show
Set PDDoc = AvDoc.GetPDDoc()
Set jso = PDDoc.GetJSObject
'Get cart ID
jso.getField("Feld1").Value = CStr(ActiveSheet.Range("B12").Value)
'Get Project ID
jso.getField("Feld2").Value = CStr(ActiveSheet.Range("B14").Value)
...
My question is: is there any possibility to use an embedded object with AcroExch.AVDoc?
Since parameter szFullPath requires the full path of the file to open, I thought about getting the "path" of the object and use it - but I cannot figure out how. Already tried this: https://danny.fyi/embedding-and-accessing-a-file-in-excel-with-vba-and-ole-objects-4d4e7863cfff
Maybe someone can help me with this.
Thanks in advance!

Replace all in a specific folder

In my Test Plan I have two folders. One with all my active test cases and one with all my archived test cases. I need to replace a lot of 'Affected Module' from one value to another, however - I don't want the folder with archived to be affected by this.
So, is there a way of doing search and replace only on a specific folder (and all the sub-folders) in HP ALM?
As far as I know the search and replace function in grid view replaces all instances of the value so I can't use that directly.
Here is a simple OTA code that updates the field ts_user_04 for all the test case in folder Subject\Automated and its sub-folder from whatever value to Quoting.
Please, change the column name as per your requirement. You can easily find the DB column for any field in HP ALM by going to the Management tab if you have access to it. Even otherwise you can get all the mapping by using OTA. (I hope you have the necessary access)
Inorder to run the OTA code, you need to install ALM Connectivity add-in which you can get it from the tools section in your ALM home page
Public TDconnection
Public reqPath
Public testPath
'Call the main Function
updateAllTests
Public Function login()
Dim almURL, almUserName, almPassword, domain, project
almURL = "https://.saas.hp.com/qcbin/"
almUserName = ""
almPassword = ""
domain = ""
project = ""
testPath = "Subject\Automated" ' Change it as per your folder structure
Set TDconnection = CreateObject("tdapiole80.tdconnection")
TDconnection.ReleaseConnection
TDconnection.InitConnectionEx almURL
TDconnection.login almUserName, almPassword
TDconnection.Connect domain, project
End Function
Public Function updateAllTests()
login
Set TreeMgr = TDconnection.TreeManager
Set TestTree = TreeMgr.NodeByPath(testPath)
If Err.Number = 0 Then
Set comm = TDconnection.Command
comm.CommandText = "update test set ts_user_04='Quoting' where ts_test_id in (select ts_test_id from test, all_lists where ts_subject in (select al_item_id from all_lists where al_absolute_path like (select al_absolute_path from all_lists where al_item_id=" & TestTree.NodeID & ") || '%' ) and ts_subject = al_item_id)"
comm.Execute
End If
logout
MsgBox "Flag Update successful", vbInformation
End Function
Public Function logout()
TDconnection.Disconnect
TDconnection.logout
TDconnection.ReleaseConnection
Set TDconnection = Nothing
End Function

How to check whether a input string is a File name or Folder name using Vbscript

My objective is to find whether the given input is s file name or folder name using Vb script.
For example if user gives "D:\Temp\testfile.docx" then it should navigate to File Related Function,
Similarly if user gives "D:\Temp\" then it should navigate to Folder Related Function.
If there is no straightforward solution, Is there any work around to do this ?
Check whether the user input refers to an existing file (.FileExists) or folder (.FolderExists):
If FolderExists(userinp) Then
folderaction
Else
If FileExists(userinp) Then
fileaction
Else
handle bad user input
End If
End If
If that doesn't fit your needs, ask the user to identify folders by always appending "\" and check Right(userinp, 1).
I created this simple function that should suit your needs:
'Return 1 if the provided path is a folder, 2 if it's a file, and -1 if it's neither.
Function GetTypeOfPath(strToTest)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If(objFSO.FolderExists(strToTest)) Then
GetTypeOfPath = 1
ElseIf(objFSO.FileExists(strToTest)) Then
GetTypeOfPath = 2
Else 'neither
GetTypeOfPath = -1
End If
End Function
You can test it by creating a file "c:\test" and running `MsgBox(GetTypeOfPath("c:\test"))"; it will return 2. Then delete that file, create a folder "c:\test" and run the same thing; it will return 1. Then delete that and run it a third time; it will return -1.

Resources