TMACUL

CA SDM Trabalhando com WebService

Blog Post created by TMACUL Champion on Sep 30, 2015

Requirement: Create a request, change Order and Contact through Web Services

Scripting- VB

Step1: Create a web reference in the front end.

Start the front end.
Go to Website menu and click “Add web reference”.
In the URL box provide the web service URL and click go.http://:8080/axis/services/USD_R11_WebService?wsdl”’
We can find the methods being pulled out.
Add the webreference with the name “WebReference”.

Lendo retorno XML Retorno WebService – Read return XML doselect
”’ <summary>
”’ Leitura do XML de retorno do WebService do CA-USD, Criado por Tiago MACUL 02/2008
”’ </summary>
Private Function LerXMLca(ByVal strXML As String) As Data.DataRow

‘ Proc que procura no xml por determinado objetos , passando pra respectivas variaveis
Dim ds As Data.DataSet
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow

dr = dt.NewRow
ds = FnStrXmlToDataset(strXML)

dr.Table.NewRow()

Dim sNome As String = “”
Dim intTables As Integer
Dim intRows As Integer = 0

For intTables = 0 To ds.Tables.Count – 1

Select Case ds.Tables(intTables).TableName
Case “UDSObject”
dr.Table.Columns.Add(“Handle”)
dr(“Handle”) = ds.Tables(0).Rows(0).Item(0)
Case “Attribute”
For intRows = 0 To ds.Tables(intTables).Rows.Count – 1
sNome = ds.Tables(intTables).Rows(intRows).Item(“AttrName”)
dr.Table.Columns.Add(sNome)
dr(sNome) = ds.Tables(intTables).Rows(intRows).Item(“AttrValue”)
Next
End Select
Next
Return dr
End Function

CRIANDO UM NOVO REQUEST, Problem or Incident
‘txtcategoria.Text == objeto criado na tela ex :pcat:5103
‘Tipo = attrVal += {“type”, “crt:182”} (page 50)
‘crt:180 = Request;
‘crt:181 = Problem available only with the ITIL installation;
‘crt:182 = Incident available only with the ITIL installation

‘Insert group = group_id
‘{“group”, “cnt:7558700F85FB2143B03D306D3CEF904D”}

Dim usd As New localhost.USD_WebService
‘usd.Url =
Dim Sid As Integer
Dim Result As String = “”
Dim attr(20) As String
Dim username, password As String
Dim resposta As String
Dim type As String
Dim category As String
Dim description As String

username = txtuser.Text ‘ServiceDesk
password = txtsenha.Text ‘ServiceDesk
type = txttype.Text
category = txtcategoria.Text
description = txtdescricao.Text

Sid = usd.login(username, password)

Dim userhandle As String
userhandle = usd.getHandleForUserid(Sid, username)

Dim attrVal(10), attr2(1), prop(1)
Dim requestHandle, requestNumber As String
attrVal = New String() {“customer”, userhandle, “category”, category, “description”, description, “type”, “crt:182”, “zrepmeth”, “400001”, “group”, “cnt:7558700F85FB2143B03D306D3CEF904D”}
prop = New String() {}
attr2 = New String() {}
requestHandle = “”
requestNumber = “”

Try
usd.createRequest(Sid, userhandle, attrVal, prop, “”, attr2, requestHandle, requestNumber)
resposta = “Executado com Sucesso ! requestHandle = ” & requestHandle & ” requestNumber = ” & requestNumber
Catch ex As Exception
resposta = Err.Number.ToString & ” – ” & Err.Description & ” – ” & ex.Message
End Try
txtResposta.Text = resposta

Criando novo registro – Create new row in Custom Table
Dessa mesma maneira é possível acessar outros objetos

Dim USD As New localhost.USD_WebService ‘Referência do WebService do CA USD
Sid = USD.login(User, pass) ‘Login no USD, pega session ID
userHandle = USD.getHandleForUserid(Sid, User)

Dim updateFailArray(9) As String
Dim Attributes(1) As String
Dim ObjResult As String = “”
Dim ticket_handle As String = “” ‘Referência do objeto que será criado

‘Atribuição dos valores para atualização da tabela
updateFailArray(0) = “campo1”
updateFailArray(1) = “Valor1”
updateFailArray(2) = “campo2”
updateFailArray(3) = “valor2”
updateFailArray(4) = “campo3”
updateFailArray(5) = “valor3”

USD.createObject(Sid, “zcustom_table”, updateFailArray, Attributes, ObjResult, ticket_handle)

Atualizando um Objeto – Update object

Dim USD As New localhost.USD_WebService ‘Referência do WebService do CA USD
Sid = USD.login(User, pass) ‘Login no USD, pega session ID
Dim updateArray3(14) As String ‘
Dim updateArray4(14) As String
Dim ticket_handle As String = “” ‘Referência do objeto que será alterado
updateArray3(0) = “zmax_num”
updateArray3(1) = “1”
updateArray3(2) = “summary”
updateArray3(3) = “titulo do chamado”
USD.updateObject(Sid, ticket_handle, updateArray3, updateArray4)

Fechando um chamado

Dim USD As New localhost.USD_WebService ‘Referência do WebService do CA USD
Sid = USD.login(User, pass) ‘Login no USD, pega session ID
Dim ticket_handle As String = “cr:1001” USD.closeTicket(Sid, “ticket fechado”, ticket_handle)

Anexo URL

Dim USD As New localhost.USD_WebService ‘Referência do WebService do CA USD
Sid = USD.login(User, pass) ‘Login no USD, pega session ID
USD.attachURLLink(Sid, 0, “URL”, “URLName”, “Descrição”)
‘usd.createLrelRelationships()

Anexo URL

Dim updateAttach(14) As String
Dim updateAttach2(1) As String
Dim objResultAttach As String = “”
Dim newHandleAttach As String = “”

Try

updateAttach(0) = “description”
updateAttach(1) = docUrl
updateAttach(2) = “orig_file_name”
updateAttach(3) = docUrl
updateAttach(4) = “attmnt_name”
updateAttach(5) = “nome do anexo”
updateAttach(6) = “attmnt_name”
updateAttach(7) = “LINK_ONLY”

USD.createObject(Sid, “attmnt”, updateAttach, updateAttach2, objResultAttach, newHandleAttach)

Catch ex As Exception

End Try

Link Anexo URL

Dim objs(0) As String
objs(0) = newHandleAttach ‘ “attmnt:400014”
Try
usd.createLrelRelationships(Sid, “cr:400001”, “attachments”, objs)
Catch ex As Exception
TextBox1.Text = ex.Message & ” – ” & Err.Number & ” – ” & Err.Description
End Try

Criando LOGs

Dim USD As New localhost.USD_WebService ‘Referência do WebService do CA USD
Sid = USD.login(User, pass) ‘Login no USD, pega session ID
USD.createActivityLog(Sid, creator, ticket_handle, strWklgDesc, logType, 0, False)

Lendo Relacionamentos – LRel

Dim usd As New localhost.USD_WebService
Dim Sid As Integer
Dim Result As String = “”
Dim attr(20) As String
Sid = usd.login(“ServiceDesk”, “ServiceDesk”)
Try
Result = usd.getLrelValues(Sid, “chg:400001”, “asset”, 0, -1, attr)
Catch ex As Exception
MsgBox(Err.Number.ToString & ” – ” & ex.Message)
End Try
msgbox(Result)

factory names ::. See page 40
Object NameFactory NameTable Name DB
Contact/Groupcntca_contact
Assetnr
Organizationorg
Locationloc
Company/Vendorca_cmpny
Modelmfrmod

 

Post Original

Trabalhando com o WebService do SDM – Tiago Macul

 

 

Saiba mais:

Web Services Best Practices for CA Service Desk Manager (CA SDM)

Outcomes