Forum Discussion
Delay web query until condition met from another web query
- 7 years ago
Hi Anonymous,
I've prepared a template which you can use for solving your problem.
You have to add your logic for processing JSON responses and modify the WaitForList according your needs.
let // request data RequestDataRecord = fnProcessJson(Web.Contents("request data URL")), // wait 10x for 5 seconds WaitForList = List.Repeat({5}, 10),
// wait until the response is COMPLETE, but max 50 secs WaitForStatus = List.MatchesAny( WaitForList, each Function.InvokeAfter( () => fnProcessJson(Web.Contents("http://StatusCheckURL")), #duration(0,0,0,_) ) = "COMPLETE" ), // download file if WaitForStatus was successful DownloadFile = if WaitForStatus then fnProcessJson(Web.Contents("download data URL")) else null in DownloadFile
Hi Anonymous,
I've prepared a template which you can use for solving your problem.
You have to add your logic for processing JSON responses and modify the WaitForList according your needs.
let
// request data
RequestDataRecord = fnProcessJson(Web.Contents("request data URL")),
// wait 10x for 5 seconds
WaitForList = List.Repeat({5}, 10),
// wait until the response is COMPLETE, but max 50 secs
WaitForStatus = List.MatchesAny(
WaitForList,
each
Function.InvokeAfter(
() => fnProcessJson(Web.Contents("http://StatusCheckURL")),
#duration(0,0,0,_)
) = "COMPLETE"
),
// download file if WaitForStatus was successful
DownloadFile =
if WaitForStatus then
fnProcessJson(Web.Contents("download data URL"))
else
null
in
DownloadFile- Anonymous7 years agoNot applicable
Thanks, Nolock
Looks like this will do the job, just working through it at the moment.
What should the output of the function in the middle be? Should it be text? a list?I think that's where I'm failing now..
- Nolock7 years agoResident Rockstar
Hi Anonymous,
do you mean this function?
() => fnProcessJson(Web.Contents("http://StatusCheckURL"))The result should be the status (i.e. COMPLETE, INPROGRESS, FAILED, ...) and its datatype is text because I compare it with the string "COMPLETE" on the next line.
But you can modify the code in a form which fulfils all your expectations. It is just a template how it could work.
- Anonymous7 years agoNot applicableYep, that's the function. So.. I created the function, the output is text "COMPLETE" .
I'm not sure what odds going wrong, I still get the "null" output.
- Anonymous7 years agoNot applicable
The first response you wrote was correct, I just wasn't calling my function correctly!
Thanks for your help. - ayangain172 years agoNew Member
Now it doesn't seem to work is there any workaround? the response is not getting updated so null is being returned always, but in postman the response gets completed within few seconds