I'm trying to loop through the JSON where I have sid which is initially zero when it is passed through the Stored Procedure it will return some value 8463 and I want to keep this value as sid and again I want to pass the same value which is 8463 through the SP again.
I have tried keeping it constant but once it loop through the one dictionary it automatically increasing the value of sid Any help would be appreciated
Views.py
@api_view(['POST'])
def SaveUserResponse(request):
if request.method == 'POST':
for ran in request.data:
print(type(ran),'QId--',ran.get('QId'), ran)
print(type(request.data))
auditorid =ran.get('AuditorId')
print('SaveUserResponse auditorid---', auditorid)
ticketid = ran.get('TicketId')
qid = ran.get('QId')
answer = ran.get('Answer')
sid = '0'
cursor = connection.cursor()
cursor.execute('EXEC [dbo].[sp_SaveAuditResponse] @auditorid=%s,@ticketid=%s,@qid=%s,@answer=%s,@sid=%s',
(auditorid,ticketid,qid,answer, sid))
result_st = cursor.fetchall()
print('sp_SaveAuditResponse', result_st)
# # if qid != 1 or qid != 42:
for row in result_st:
print('sp_SaveAuditResponse', row)
sid = row[0]
return Response(row[0])
Payload:
[{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":42,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":43,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":44,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":45,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":46,"Answer":"3","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":47,"Answer":"5","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":48,"Answer":"5","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":49,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":50,"Answer":"5","SID":"0","Comments":""}]