SOAP - convert Python dictionary to tabel

When using SOAP to recipe a message from our ERP, I get a dictionary header that looks like this

{“Root”: {“ReadMultiple_Result”: {“ReadMultiple_Result”: {“employ”: [
“Comment”: false,
“First_Name”: “Piranan”,
“FullName”: “Piranan Sriratya”,
“Initials”: “HJA”,
“Job_Title”: “Accounting”,
“Key”: “20;UBQAAAJ7BDAAMA0wADE=7;87293340;”,
“Last_Name”: “Sriratya”,
“Mobile_Phone_No”: “0891557097”,
“No”: “0001”,
“Phone_No”: “0891557807”,
“Resource_No”: “0001”,
“Search_Name”: “NAN”

I’m trying to convert it into a table, like this

def dictToDataset(dictValue):
data = []
columns = dictValue[“employ”][0].keys()
for obj in dictValue[“Root”]:
row = []
for column in columns:
return system.dataset.toDataSet(columns,data)

table = event.source.parent.getComponent(‘Table’)
wsrespons =‘testt’)
Dic = = dictToDataset(Dic)

If I manuel edit the header to just contain “employ” then it working ok, but how to get the key from the original respons, ?

Is that the actual text of the response you get? It looks more like JSON than a SOAP response so if that is it you should be able to do:

data = """
	"Root": {
		"ReadMultiple_Result": {
			"ReadMultiple_Result": {
				"employ": [{
					"Comment": false,
					"First_Name": "Piranan",
					"FullName": "Piranan Sriratya",
					"Initials": "HJA",
					"Job_Title": "Accounting",
					"Key": "20;UBQAAAJ7BDAAMA0wADE=7;87293340;",
					"Last_Name": "Sriratya",
					"Mobile_Phone_No": "0891557097",
					"No": "0001",
					"Phone_No": "0891557807",
					"Resource_No": "0001",
					"Search_Name": "NAN"

js = system.util.jsonDecode(data)

print js['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ'][0]
1 Like

Hi, yes, I get the data in via sepasoft soap web service, but it decodes fine with your suggestion, thanks :-):

My final code, reading from Dynamic Navision2013, reading employee list via sepasoft web service

def dictToDataset(dictValue):
data = []
columns = dictValue[‘Root’][‘ReadMultiple_Result’][‘ReadMultiple_Result’][‘employ’][0].keys()

i = 0
for obj in dictValue['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ']:
	row = []
	for column in columns:
		if column in dictValue['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ'][i].keys():
	i = i + 1
return system.dataset.toDataSet(columns,data)

table = event.source.parent.getComponent(‘Table’)

wsrespons =‘employ’)
string = wsrespons.toString()
js = system.util.jsonDecode(string) = dictToDataset(js)

Ah I see I’ve led you astray a bit in this regard since the Sepasoft webservice request converts the SOAP response into a JSON-ish looking structure when stringified.

If you’re willing to play with it a bit more you can probably simplify your code and reduce a lot of the processing needed by doing something more like this:

table = event.source.parent.getComponent('Table')

wsrespons ='employ')
root = wsresponse.getChild("Root")
r1 = root.getChild("ReadMultiple_Result")
r2 = f1.getChild("ReadMultiple_Result")
employees = r2.getChild("employ") = employees.toDataSet()
1 Like

I played a bit, and the concept is brilliant
But it looks like there is only 1 child, :frowning:

made a small script to test the file

wsrespons =‘employlist’)
root = wsrespons.hasChildren()
print root
root = wsrespons.getChildCount()
print root
root = wsrespons.getName()
print root