Highlighted
sivabalan_n Absent Member.
Absent Member.
4093 views

Can anyone provide me web services code snippet using python?

Hi Team,

I am writing a script to update some items in SBM via Web Services using Python script. If anyone have code snippet pls share.

Thanks in advance
Sivabalan N.
0 Likes
1 Reply
milan_blokar Absent Member.
Absent Member.

Re: Can anyone provide me web services code snippet using python?

Hi,

here you have short notes and incomplete and dirty (I'm NOT Python programmer)
snippets from SBM to HP PPM integration modules:

1. Use Jurko - Suds: Jurko - Suds page



from suds.client import Client
from suds import WebFault

url = 'http://localhost/gsoap/sbmappservices72.wsdl'
client = Client(url)



2. Explore structures from Python command line. Read and use SBM manuals. 😛


--------------------------------------------------------------------------------
def getInputRowAsItem(tsId):
""" query and get existing input row as item """

# Auth
ns1_auth = client.factory.create('ns1:Auth')
ns1_auth.userId = 'xxxxxxxx'
ns1_auth.password = 'xxxxxxxx'

# Table
ns1_table = client.factory.create('ns1:TableIdentifier')
ns1_table.dbName = 'USR_PPM_RESOURCE_STAFFING'

# queryWhereClause
ns1_queryWhereClause = 'TS_ID = ' + tsId

# orderByClause
ns1_orderByClause = ''

# firstRecord
ns1_firstRecord = 0

# maxReturnSize
ns1_maxReturnSize = 100

# Response
ns1_response_item_options = client.factory.create('ns1:ResponseItemOptions')
ns1_response_item_options.sections = 'SECTIONS-SPECIFIED'
ns1_response_item_options.specifiedSections = 'SECTION:FIXED'

try:
result = client.service.GetItemsByQuery(ns1_auth, ns1_table,
ns1_queryWhereClause,
ns1_orderByClause,
ns1_firstRecord,
ns1_maxReturnSize,
ns1_response_item_options)
ETC ....

-----------------------------------------------------------------------------
def updateResolvers(Item, Resource, PrimaryResolver, Tester):

# Auth
ns1_auth = client.factory.create('ns1:Auth')
ns1_auth.userId = 'xxxxxxxx'
ns1_auth.password = 'xxxxxxxx'

# Item (with TITLE, ISSUETYPE)
ns1_item = client.factory.create('ns1:TTItem')
ns1_item = Item

# Transition (empty -> default submit)
ns1_transition = client.factory.create('ns1:TransitionIdentifier')
ns1_transition.internalName = 'SDSPECIALISTWORKFLOW.DEADLINE_UPDATE'

# breakLock
ns1_breakLock = 'True'

# PRIMARY_RESOLVER
ws_PrimaryResolver = client.factory.create('ns1:NameValue')
ws_PrimaryResolver.id.dbName = 'PRIMARY_RESOLVER'
ws_PrimaryResolver.setValueBy = 'DISPLAY-VALUE'
ws_PrimaryResolver.setValueMethod = 'REPLACE-VALUES'
ns_PrimaryResolverValue = client.factory.create('ns1:FieldValue')
ns_PrimaryResolverValue.displayValue = Resource
ws_PrimaryResolver.value = ns_PrimaryResolverValue

# TESTER
ws_Tester = client.factory.create('ns1:NameValue')
ws_Tester.id.dbName = 'TESTER'
ws_Tester.setValueBy = 'DISPLAY-VALUE'
ws_Tester.setValueMethod = 'REPLACE-VALUES'
ns_TesterValue = client.factory.create('ns1:FieldValue')
ns_TesterValue.displayValue = Resource
ws_Tester.value = ns_TesterValue

# SUPPORT_RESOLVERS
ws_SupportResolvers = client.factory.create('ns1:NameValue')
ws_SupportResolvers.id.dbName = 'SUPPORT_RESOLVERS'
ws_SupportResolvers.setValueBy = 'DISPLAY-VALUE'
ws_SupportResolvers.setValueMethod = 'APPEND-VALUES'
ns_SupportResolversValue = client.factory.create('ns1:FieldValue')
ns_SupportResolversValue.displayValue = Resource
ws_SupportResolvers.value = ns_SupportResolversValue

# Response
ns1_response_item_options = client.factory.create('ns1:ResponseItemOptions')
ns1_response_item_options.sections = 'SECTIONS-SPECIFIED'
ns1_response_item_options.specifiedSections = 'SECTION:FIXED'

if PrimaryResolver == 'Y':
ns1_item.extendedField = (ws_SupportResolvers, ws_PrimaryResolver)
elif Tester == 'Y':
ns1_item.extendedField = (ws_SupportResolvers, ws_Tester)
else:
ns1_item.extendedField = (ws_SupportResolvers)

try:
result = client.service.TransitionItem(ns1_auth, ns1_item,
ns1_transition, 1,
ns1_response_item_options)
ETC ....

---------------------------------------------------------------------------

# get Item
currentInputItem = getInputRowAsItem(str(tsId))

# update Item
isOK = updateResolvers(currentInputItem[1].item[0], ETC ...)

---------------------------------------------------------------------------



Anyway, Python & SBM webservices are (for me) better alternative to complex orchestrations.
They seem to me as a good choice for integrating SBM with other tools, especially
when some SBM funcionality is needed (transitions, notifications, attaching files etc.)
Do not expect speed of app script or (unsupported) direct database updates.

Regards,

Milan
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.