cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a result from a post webscript to a get webscript

itzamna
Confirmed Champ
Confirmed Champ
Hi all,

I'm facing the following challange: I've a GET web-script that returns a  set of documents from a Javabacked script in Share. The documents will be displayed in a table to the user. Now, the user is able to select from a dropdown a number of documents that should be displayed (pre-defined as: 50, 100, 250) and also to select a filter of available document types.
I'm able to post the submitted values of the webform (myshare.get.html.ftl) via a POST (myshare.post.js) to Alfresco (see below), query the database based on the specified arguments and return a JSON with the results. So the "result" below contains a long JSON with all search results that was requested by the user:

Snippet of my myshare.post.js:
<javascript>
function execute(jsonString)
{
   logger.log("JSONString that will be send to Alfresco: " + jsonUtils.toJSONString(jsonString));
   var connector = remote.connect("alfresco");   
   var result = connector.post("/com/company/feature/share?type=" + jsonUtils.toJSONString(jsonString), "application/json");
        var resultObject = jsonUtils.toObject(result.response);
        //resultObject["searchResults"]; ==> contains the evaluated result with all documents of the users request
   if (result.status == 200)
        {
             var res_status = resultObject["status"];
             if (res_status == "OK")
             {         
                status.setCode(302); //303,307,308
                status.setLocation(url.context + "/page/console/myfeature/myshare");
                status.setRedirect(true);
                return;
             }
        }

</javascript>

My problem currently: After re-directing back to my GET webscript (setLocation(…)) the initial Javabacked script will be invoked again and return the default results. So, the user can select anything he wants but he'll getting always the default search result of the GET webscript… How I'm able to "overwrite" these values (in this case a map)? I've checked the http://wiki.alfresco.com/wiki/Web_Scripts_Examples but there are only some examples (like the blog search) that set always only one parameter with one value. I've a large map as JSON that must be given back to the GET webscript.
What is the best way to pass such a result from a POST webscript to a GET webscript?
Just passing it as a parameter like

status.setLocation(url.context + "/page/console/myfeature/myshare?result=" +jsonUtils.toObject(resultObject["searchResults"]));

is not a good idea I assume because the result can be some Miles long…

Thanks for any hint.

Itzamna

3 REPLIES 3

itzamna
Confirmed Champ
Confirmed Champ
Nobody has a clue?
Maybe let me explain it in a different way on the use-case:

I've a GET webscript that displays a table with 10 documents (name, title, description, originator) to the user. Now the user is able to select from a dropdown (near the table) a different number of documents he wants to see, let's say 50 for example. If he has selected the new value he submits the formular.
Now, I want to receive the value to query the database with it (compare above to the snippet "function execute(jsonString)").
It all works fine. I receive the value in my POST webscript, I'm able to query the db and I'm able to provide the new results as JSON in the POST webscript (resultObject["searchResults"]; above).
But now: How do I get the result back to the GET webscript where the presentation is already implemented? I don't think the solution can be to duplicate the myshare.get.html.ftl and rename it to myshare.post.html.ftl so that I have to maintain the presentation logic always twice?


Am I wrong with my approach? What is an approach to solve such a request?

zafarale
Champ in-the-making
Champ in-the-making
Call same get script with parameters to limit your results

mrogers
Star Contributor
Star Contributor
Why have you got two web scripts?    If you use multiple scripts then you will need to persist data somewhere so you can work on it.     In a single get script the script controller brings together the data from various sources before displaying the result.