Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] tRESTResponse returning 404 when no records found

Hi all, 
I want to have multiple tRestResponse component for each of my sujobs:  if a record exists in my db, I should have a 200 http status code, else, it should be  404.
T tried a little thing (please find attached the screenshots) but I'm always having a 404 http status code. 
thank you for your help
Cheers 0683p000009MDu3.png 0683p000009MDbr.png 0683p000009MDhC.png
Labels (5)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I'm afraid globalMap variables don't work like that. You either need to set them in Java code or using the tFlowToIterate or tSetGlobVar components. 
You can achieve your goal using the tFilterRow solution I suggested earlier. You simply need to set a boolean (or something else) in your tXMLMap to indicate the status of your FilmId query. Then pass that status out with the body Document. If the boolean is true, then filter it to go to the tRESTResponse with code 200, if it is false filter it to go to the tRESTResponse with code 404.
From memory, I believe you are sending the FilmId to the child job to be used in the tMySQLInput query. If you engineer that query so that it will always return a row regardless of whether the film is found or not, you can use the response in your tXMLMap to decide whether it is successful or not. Use that logic to set the boolean. Then, instead of having more than one output from the tXMLMap, have one output with the success/failure flag. Use that column with the tFilterRow component and then just map the filter/reject outputs to the appropriate tRESTResponse.

View solution in original post

17 Replies
Anonymous
Not applicable
Author

*I tried to print the value of the ((Boolean)globalMap.get("FilmId")); it's always NULL !!
0683p000009MDcL.png 0683p000009MDu8.png
Anonymous
Not applicable
Author

Basically, the data flow goes to both of the tRESTReponse components whether there is anything to output or not. You need to filter the flow.
Try using a tFilterRow to send the the data to the 200 or 404 output. You can filter on the boolean that you are filtering in the tMap at the moment. See below...
0683p000009MDlw.png
Anonymous
Not applicable
Author

Well, if I filter on the boolean, I get a 500 server error on soap ui: 
0683p000009MDez.png 0683p000009MDid.png
if I filter on the "film_id" that I want to retrieve, I get always a 404 status code, 
0683p000009MDuD.png 0683p000009MDof.png
and finally, if I remove the row "film_id" in the tfilterRow schema, I get always a 200 status code, even if the record doesn't exist in the db.
Regards
Anonymous
Not applicable
Author

That is because the Boolean you are passing back is actually NULL. Your problem looks like it is centred on the ((Boolean)globalMap.get("FilmId")) .  How are you setting this value and in which Job (parent or child)? 
Anonymous
Not applicable
Author

actually I thought it's a global variable that automatically stores the state of the excution of a component, for example, if my tRunJob  "FilmId" has been executed well, automatically ((Boolean)globalMap.get("FilmId)) would be true. So I haven't set that variable anywhere
Anonymous
Not applicable
Author

The way I've been thinking the whole thing was wrong. The tests that I made, concern "whether the subjob was successfully completed or not", and it works if I see it that way. 
However, I don't want to test whether the job was successfull or not, I want to have  404 status error if the record I want to retrieve doesn't exist==> the job will be successfull but I'll have no results 
could you help me with this please
Thank you for your time
Anonymous
Not applicable
Author

I'm afraid globalMap variables don't work like that. You either need to set them in Java code or using the tFlowToIterate or tSetGlobVar components. 
You can achieve your goal using the tFilterRow solution I suggested earlier. You simply need to set a boolean (or something else) in your tXMLMap to indicate the status of your FilmId query. Then pass that status out with the body Document. If the boolean is true, then filter it to go to the tRESTResponse with code 200, if it is false filter it to go to the tRESTResponse with code 404.
From memory, I believe you are sending the FilmId to the child job to be used in the tMySQLInput query. If you engineer that query so that it will always return a row regardless of whether the film is found or not, you can use the response in your tXMLMap to decide whether it is successful or not. Use that logic to set the boolean. Then, instead of having more than one output from the tXMLMap, have one output with the success/failure flag. Use that column with the tFilterRow component and then just map the filter/reject outputs to the appropriate tRESTResponse.
Anonymous
Not applicable
Author

Okey, I'll work on it. 
I built the parent and the subjobs, but I can't access them from the browser; I get an "inaccessible web page", is that normal??!!
that wasn't the case when I had just one job.. 
Anonymous
Not applicable
Author

That doesn't sound right, but I'm confused by the use of a browser?? If you meant you are having issues opening the Job in the Studio, just restart the Studio. It can be a bit quirky sometimes, especially if it has been left on for a while.