User's Requirement
The need is to have an automatic procedure to create NEW users into Quality Center, linking them to a Project and give them one or more profiles (groups).
Proposed Solution
Creation of an External Procedure out of the WorkFlow Script Editor using SiteAdmin API retrieve information to create users from en Excel Sheet.
This procedure will be a .vbs file (vbscript).
__________________________________________________________________________
Implementation OUTSIDE the Product
This time we'll not write code using Script Editor but we'll create an external vbs file as I mentioned in Proposed Solution. This proc will do these operations:
These information will be retrieve from an Excel Sheet that will contains these informations:
Suppose Excel FileName is myFile.xls and it is located into "c:\temp" folder.
This is the entire code:
'************************************************************
' CONSTANTS DECLARATION
'************************************************************
Const server = "http://QCAddress/qcbin"
Const user = "qcadmin"
Const psw = "xxxxxxx"
'************************************************************
'************************************************************
' VARIABLES DECLARATION
'************************************************************
Dim mySaApi, XLS, Wkb, Wks, xmlCheckUsr, myXMLString, arrRole, j, i
'************************************************************
'************************************************************
'************************************************************
'************************************************************
'Retrieve the SiteAdminApi Interface
set mySaApi = CreateObject("SAClient.SAapi")
'Login
mySaApi.login server, user, psw
'Create excel object to manage excel file
set XLS = CreateObject("Excel.Application")
XLS.Visible = False
'Open excel File (suppose the file is "C:\temp\myFile.xls")
Set Wkb = XLS.Workbooks.Open("C:\temp\myFile.xls")
Set Wks = Wkb.WorkSheets(1)
'Do a loop for each row of the excel file
i = 2
do while (wks.Cells(i,1).Value <> "")
'For each row create the new user and Add it to the Project
'Check if User already exists
on error resume next
err.clear
xmlCheckUsr = mySaApi.GetUser(wks.Cells(i,1).Value)
if err.number <> 0 then
'user does not exist. I create it.
myXMLString = ""
myXMLString = mySaApi.CreateUser(wks.Cells(i,1).Value, _
wks.Cells(i,2).Value, _
wks.Cells(i,3).Value,
_
wks.Cells(i,4).Value, _
wks.Cells(i,5).Value, _
wks.Cells(i,6).Value)
end if
on error goto 0
'7. Add the role(s) to the user
'Firstable I link the user to the Project
mySaApi.AddUsersToProject wks.Cells(i,7).Value, _
wks.Cells(i,8).Value, _
wks.Cells(i,1).Value
'I analyze the 9th field, the Roles
if instr(wks.Cells(i,9).Value, ",") then
arrRole = split(wks.Cells(i,9).Value,",")
for j=0 to ubound(arrRole)
'add the role to the user
mySaApi.AddUsersToGroup wks.Cells(i,7).Value, _
wks.Cells(i,8).Value, _
arrRole(j), _
wks.Cells(i,1).Value
next
else
mySaApi.AddUsersToGroup wks.Cells(i,7).Value, _
wks.Cells(i,8).Value, _
wks.Cells(i,9).Value, _
wks.Cells(i,1).Value
end if
i = i + 1
loop
'Logout from SiteAdmin
mySaApi.Logout
'destroy SaApi object
set mySaApi = Nothing
'close excel file and quit excel application
wkb.close
XLS.Quit
'************************************************************
'************************************************************
'************************************************************
Pag: >
Questo sito è stato realizzato con Jimdo! Registra il tuo sito gratis su https://it.jimdo.com