Skip to main content

Return multiple values from script result

Comments

3 comments

  • Zendesk API User
    Author: mbergmann - 11/15/2017 16:00

    Hi Andres,

    $CMS_RENDER$ will directly render the result into the output, you cannot use the renderscript's result as a variable in the template.

    But there is a kind of workaround: Just provide some empty container as parameter to the script. In your case an empty list seems a good choice, empty sets or maps can also be used:

    $CMS_SET(set_result,[])$

    $CMS_RENDER(script:"....", resultContainer:set_result)$

    In the script, you then have access to the variable "resultContainer" (or whatever you name it) and add the information to it:

    resultContainer.add(project.getName());

    To avoid any output by the script itself, you should also add

    result.setValue("");

    at the end because otherwise the value of the last expression in the script might get output.

    Then, "back" in the template (=after the CMS_RENDER call), the variable "set_result" has been populated by the script and you could for example iterate over it:

    $CMS_FOR(for_projectName, set_result)$

         $CMS_VALUE(for_projectName)$

    $CMS_END_FOR$

    You can - of course - also use something simpler, the for loop was just for clarification. It's important that the "container" is defined in the template so that you can access it from there after the script has put some values into it. And, by the way, you could also out other objects there, not only strings.

    Michael

    0
  • Zendesk API User
    Author: rednoss - 11/29/2017 10:37

    Hello Andres,

    do you need further help or did Michael's reply already help you? If so, it would be great if you marked his reply as "correct answer" so that other community users find the solution easily. If you have already found a solution by yourself, it would be very kind of you, if you posted it here.

    Best regards

    Rene

    0
  • Zendesk API User
    Author: agarcia - 2/22/2018 9:31

    Sorry for the late answer, I wasn't able to try it till now.

    But I must say it worked like a charm! :smileyhappy:

    Thank you, Michael.

    0

Please sign in to leave a comment.