A follow on question:
The Dictionary has basically 3 levels and using the strategy given before, I’m able to get all of the rows from the second and third levels. But I am not able to use the script for the first level. I’ve come up with a temporary work around (Select 1, 2 3) but would rather not use this in the long run. As you can see in the below script, I’m getting the data from “data” and operDict. I’ve tried setting up the “data” portion of the script with the newrow type stuff from later in the script but it fails. Any ideas?
from urllib import urlencode
from datetime import datetime
FMT = '%Y-%m-%d %H:%M:%S'
if event.source.parent.getComponent('Select 1').selected:
x = 0
if event.source.parent.getComponent('Select 2').selected:
x = 1
if event.source.parent.getComponent('Select 3').selected:
x = 2
#Salord = event.source.parent.getComponent('Work_Order').selectedStringValue
Salord = event.source.parent.getComponent('WO_List').selectedStringValue
args = {"sales-order": Salord, "token": "cfapiKnJ4Td2WQ8hf"}
Server = event.source.parent.getComponent('Table_Select').Server
response = system.net.httpGet("http://" + Server + ":8080/cellfusion/api/v1/orders/details?" + urlencode(args))
#stores jsonString into a python object/dict
jsonDict = system.util.jsonDecode(response)
#Assigns the variable, data, to the dictionary inside of jsonDict
data = jsonDict['data'][x]
operDict = jsonDict['data'][x]['operations']
id = str(data['id'])
mfgstatusCode = str(data['mfgstatus-code'])
assemblyid = str(data['assembly-id'])
assemblyCode = str(data['assembly-code'])
qty = str(data['mfgqty'])
description = str(data['assembly-dscr'])
workorder = str(data['salord'])
status = str(data['mfgstatus-dscr'])
opsopen = str(data['opsopen'])
opsclosed = str(data['opsclosed'])
currentop = str(data['currentop-code'])
laborhrs = str(round(data['actualtime']/3600.0,2))
headers = ['ID', 'Status Code', 'Assembly ID', 'Top Level PN', 'Quantity', 'Description', 'Work Order', 'Status', 'Ops Open', 'Ops Closed', 'Current Op', 'Labor Hrs' ]
rows = [
[ id, mfgstatusCode, assemblyid, assemblyCode, qty, description, workorder, status, opsopen, opsclosed, currentop, laborhrs ] ,
]
dataset = system.dataset.toDataSet(headers, rows)
event.source.parent.getComponent('Head_Table').data = dataset
# create holder list
rows = []
for row in operDict:
newrow = []
newrow.append(row['fwork-code'])
newrow.append(row['fwork-id'])
newrow.append(row['fwork-dscr'])
newrow.append(row['from'])
newrow.append(row['to'])
try:
if row['from']:
d1 = row['from']
else:
d1 = "No Date"
except ValueError:
d1 = "No Date"
try:
if row['to']:
d2 = row['to']
else:
d2 = "No Date"
except ValueError:
d2 = "No Date"
try:
if row['from']:
newrow.append(datetime.strptime(d2, FMT) - datetime.strptime(d1, FMT))
else:
newrow.append('0')
except ValueError:
"No Value"
try:
if row['actualtime']:
newrow.append(round(row['actualtime']/3600.0,2))
else:
newrow.append('0')
except ValueError:
'0'
newrow.append(row['status'])
# add our new row (casting each element to a string) to the overall rows list
rows.append([str(r) for r in newrow])
headers = ['OP Code', 'ID', 'Description', 'Start', 'End', 'Elapsed', 'Labor Hrs', 'Status']
dataset = system.dataset.toDataSet(headers, rows)
event.source.parent.getComponent('Oper_Table').data = dataset