The form related to this article demonstrates one way in which you can work with the results you get back from the API Server and iCM API worker.
The worker is called server-side as the HTML template on page 2 of the form loads.
function(helper, defaultValue, currentValue) {
let searchText = helper.queryFieldValue("PAGE1", "SEARCHTEXT");
let resp = helper.utilServerAPIServerCall("icmapi", "CSSearchMultiple_get", {
"set": {
"CollectionNameList": "Article",
"RootArticleIDs": "8540,8550,8555,8560,7350,3130",
"LuceneRepositoryPath": "http://localhost:5506/solrsite",
"Keywords": searchText
},
"get": "Key,Title"
}, {
"rawMode": true
});
return resp.data;
}
CSSearchMultiple_get takes the value of the field on page one as the "Keywords" parameter. The search is limited to the article collection, and those articles beneath article 3029 (the ID of the homepage of this knowledge base subsite).
The get request only retrieves the article ID and title. Using "*" would return all of the information held in the search index, but would be slower.
The return statement limits the result to the data we're interested in.
Results are displayed using the field's Handlebars template.
{{#if multipleItemData}}
<p>Searching on <strong>{{FIELD "SEARCHTEXT"}}</strong> found <strong>{{length multipleItemData}}</strong> results.</p>
<table>
<tbody>
<tr>
<th>Article ID</th>
<th>Title</th>
</tr>
{{#each multipleItemData}}
<tr>
<td>{{Key}}</td>
<td><a href="./{{Key}}">{{Title}}</a>
</td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<p>Sorry, <strong>{{FIELD "SEARCHTEXT"}}</strong> didn't match any articles.</p>
{{/if}}
This template uses the standard
As well as displaying the