<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Using Server-side Javascript</title><link>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Using Server-side Javascript</title><link>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript</link><pubDate>Wed, 05 Aug 2020 16:17:06 GMT</pubDate><guid isPermaLink="false">22836c74-6c77-4a15-97b1-a26123ce5aa7</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/05/2020 16:17:06&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_Server-side_Javascript" name="When_should_I_use_Server-side_Javascript"&gt;&lt;/a&gt;When should I use Server-side Javascript?&lt;/h2&gt;
&lt;p&gt;Server-side Javascript (identified with the extension .jsm) is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Server-side Javascript is an implementation of the &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;ECMAScript 5.1&lt;/a&gt; specification with access to the full Verint Community Widget/Scripting API. Javascript, and specifically Server-side Javascript, is best suited for processing of data whereas [[Using Velocity|Velocity]] is better suited for text formatting.&lt;/p&gt;
&lt;p&gt;Within a scripted customization, the scripted customization itself is executed within its own local scope with platform APIs exposed via the global scope. This means the Javascript concept &amp;quot;this&amp;quot; refers to the scripted component entry point (the current execution of the widget&amp;#39;s content script or the current execution of the theme&amp;#39;s body script, for example).&lt;/p&gt;
&lt;h2&gt;&lt;a id="Server-side_Javascript_Syntax" name="Server-side_Javascript_Syntax"&gt;&lt;/a&gt;Server-side Javascript Syntax&lt;/h2&gt;
&lt;p&gt;Server-side Javascript is a full implementation of the ECMAScript 5.1 specification. &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;Language details for ECMAScript 5.1 can be found here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_in_Server-side_Javascript" name="Widget_Extension_Usage_in_Server-side_Javascript"&gt;&lt;/a&gt;Widget Extension Usage in Server-side Javascript&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to Server-side Javascript, implemented as a set of widget extensions automatically available in the context of an executed Server-side Javascript script.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;// Retrieve the current blog. If there is none, hide the widget
var currentBlog = core_v2_blog.Current;
if (!currentBlog)
	return &amp;#39;&amp;#39;;

// Store the result in an array that we&amp;#39;ll later join to form
// the response string.
var resultHtml = [];

// Retrieve the 5 latest blog posts
var blogPosts = core_v2_blogPost.List({ 
    BlogId: currentBlog.Id, 
    PageSize: 5 
    });

if (blogPosts.Count &amp;gt; 0) {
    resultHtml.push(&amp;#39;&amp;lt;ul&amp;gt;&amp;#39;);
    for (var i = 0; i &amp;lt; blogPosts.Count; i++) {
        resultHtml.push(&amp;#39;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&amp;#39;);
        resultHtml.push(core_v2_encoding.HtmlAttributeEncode(blogPosts[i].Url));
        resultHtml.push(&amp;#39;&amp;quot;&amp;gt;&amp;#39;);
        resultHtml.push(blogPosts[i].Title);
        resultHtml.push(&amp;#39;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#39;);
    }
    resultHtml.push(&amp;#39;&amp;lt;/ul&amp;gt;&amp;#39;);
} else {
    resultHtml.push(&amp;#39;&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;&amp;#39;);
}

// Combine the array of HTML fragments and return it
return resultHtml.join(&amp;#39;\n&amp;#39;);&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3&gt;&lt;a id="Remember_to_return" name="Remember_to_return"&gt;&lt;/a&gt;Remember to return&lt;/h3&gt;
&lt;p&gt;The result of rendering Server-side Javascript is provided via the &lt;code&gt;return&lt;/code&gt; statement which can occur anywhere within the script&amp;#39;s implementation. If implementing a widget or theme script using Server-side Javascript, be sure to&amp;nbsp;provide the result of the rendering using &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a id="You_can_return_other_types" name="You_can_return_other_types"&gt;&lt;/a&gt;You can return other types&lt;/h3&gt;
&lt;p&gt;When executing a Server-side Javascript script from another script (even from [[Using Velocity|Velocity]]) using &lt;code&gt;core_v2_widget.ExecuteFile()&lt;/code&gt;, the Server-side Javascript can return a Javascript object containing multiple values and even functions with contextual state. You can effectively create a custom scripting API by returning a complex object from an executed Server-side Javascript.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Built-in_JSON_formatting" name="Built-in_JSON_formatting"&gt;&lt;/a&gt;Built-in JSON formatting&lt;/h3&gt;
&lt;p&gt;When a string is expected (for example, when rendering the content of a widget or the response to an Ajax request), Server-side Javascript can return a complex object and the object will be automatically formatted as JSON (with any functions removed). This is a very simple way to provide JSON to custom Ajax callbacks in scripted components.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Working_with_API_Lists" name="Working_with_API_Lists"&gt;&lt;/a&gt;Working with API Lists&lt;/h3&gt;
&lt;p&gt;Lists of results from API calls are not Javascript arrays so Javascript array functions and the &lt;code&gt;.length&lt;/code&gt; property are not available. Refer to the inline documentation for the API that you&amp;#39;re using and details about its return type, but, in general, remember to use &lt;code&gt;.Count&lt;/code&gt; instead of &lt;code&gt;.length&lt;/code&gt; for API list results.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: Javascript, widgets, jsm&lt;/div&gt;
</description></item><item><title>Using Server-side Javascript</title><link>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript/revision/3</link><pubDate>Fri, 21 Jun 2019 20:18:42 GMT</pubDate><guid isPermaLink="false">22836c74-6c77-4a15-97b1-a26123ce5aa7</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript#comments</comments><description>Revision 3 posted to Developer Training by Ben Tiedt on 06/21/2019 20:18:42&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_Server-side_Javascript" name="When_should_I_use_Server-side_Javascript"&gt;&lt;/a&gt;When should I use Server-side Javascript?&lt;/h2&gt;
&lt;p&gt;Server-side Javascript (identified with the extension .jsm) is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Server-side Javascript is an implementation of the &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;ECMAScript 5.1&lt;/a&gt; specification with access to the full Verint Community Widget/Scripting API. Javascript, and specifically Server-side Javascript, is best suited for processing of data whereas [[Using Velocity|Velocity]] is better suited for text formatting.&lt;/p&gt;
&lt;p&gt;Within a scripted customization, the scripted customization itself is executed within its own local scope with platform APIs exposed via the global scope. This means the Javascript concept &amp;quot;this&amp;quot; refers to the scripted component entry point (the current execution of the widget&amp;#39;s content script or the current execution of the theme&amp;#39;s body script, for example).&lt;/p&gt;
&lt;h2&gt;&lt;a id="Server-side_Javascript_Syntax" name="Server-side_Javascript_Syntax"&gt;&lt;/a&gt;Server-side Javascript Syntax&lt;/h2&gt;
&lt;p&gt;Server-side Javascript is a full implementation of the ECMAScript 5.1 specification. &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;Language details for ECMAScript 5.1 can be found here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_in_Server-side_Javascript" name="Widget_Extension_Usage_in_Server-side_Javascript"&gt;&lt;/a&gt;Widget Extension Usage in Server-side Javascript&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to Server-side Javascript, implemented as a set of widget extensions automatically available in the context of an executed Server-side Javascript script.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;// Retrieve the current blog. If there is none, hide the widget
var currentBlog = core_v2_blog.Current;
if (!currentBlog)
	return &amp;#39;&amp;#39;;

// Store the result in an array that we&amp;#39;ll later join to form
// the response string.
var resultHtml = [];

// Retrieve the 5 latest blog posts
var blogPosts = core_v2_blogPost.List({ 
    BlogId: currentBlog.Id, 
    PageSize: 5 
    });

if (blogPosts.Count &amp;gt; 0) {
    resultHtml.push(&amp;#39;&amp;lt;ul&amp;gt;&amp;#39;);
    for (var i = 0; i &amp;lt; blogPosts.Count; i++) {
        resultHtml.push(&amp;#39;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&amp;#39;);
        resultHtml.push(core_v2_encoding.HtmlAttributeEncode(blogPosts[i].Url));
        resultHtml.push(&amp;#39;&amp;quot;&amp;gt;&amp;#39;);
        resultHtml.push(blogPosts[i].Title);
        resultHtml.push(&amp;#39;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#39;);
    }
    resultHtml.push(&amp;#39;&amp;lt;/ul&amp;gt;&amp;#39;);
} else {
    resultHtml.push(&amp;#39;&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;&amp;#39;);
}

// Combine the array of HTML fragments and return it
return resultHtml.join(&amp;#39;\n&amp;#39;);&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3&gt;&lt;a id="Remember_to_return" name="Remember_to_return"&gt;&lt;/a&gt;Remember to return&lt;/h3&gt;
&lt;p&gt;The result of rendering Server-side Javascript is provided via the &lt;code&gt;return&lt;/code&gt; statement which can occur anywhere within the script&amp;#39;s implementation. If implementing a widget or theme script using Server-side Javascript, be sure to&amp;nbsp;provide the result of the rendering using &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a id="You_can_return_other_types" name="You_can_return_other_types"&gt;&lt;/a&gt;You can return other types&lt;/h3&gt;
&lt;p&gt;When executing a Server-side Javascript script from another script (even from [[Using Velocity|Velocity]]) using &lt;code&gt;core_v2_widget.ExecuteFile()&lt;/code&gt;, the Server-side Javascript can return a Javascript object containing multiple values and even functions with contextual state. You can effectively create a custom scripting API by returning a complex object from an executed Server-side Javascript.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Built-in_JSON_formatting" name="Built-in_JSON_formatting"&gt;&lt;/a&gt;Built-in JSON formatting&lt;/h3&gt;
&lt;p&gt;When a string is expected (for example, when rendering the content of a widget or the response to an Ajax request), Server-side Javascript can return a complex object and the object will be automatically formatted as JSON (with any functions removed). This is a very simple way to provide JSON to custom Ajax callbacks in scripted components.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Working_with_API_Lists" name="Working_with_API_Lists"&gt;&lt;/a&gt;Working with API Lists&lt;/h3&gt;
&lt;p&gt;Lists of results from API calls are not Javascript arrays so Javascript array functions and the &lt;code&gt;.length&lt;/code&gt; property are not available. Refer to the inline documentation for the API that you&amp;#39;re using and details about its return type, but, in general, remember to use &lt;code&gt;.Count&lt;/code&gt; instead of &lt;code&gt;.length&lt;/code&gt; for API list results.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Server-side Javascript</title><link>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript/revision/2</link><pubDate>Fri, 21 Jun 2019 20:12:53 GMT</pubDate><guid isPermaLink="false">22836c74-6c77-4a15-97b1-a26123ce5aa7</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript#comments</comments><description>Revision 2 posted to Developer Training by Ben Tiedt on 06/21/2019 20:12:53&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="When_should_I_use_Server-side_Javascript" name="When_should_I_use_Server-side_Javascript"&gt;&lt;/a&gt;When should I use Server-side Javascript?&lt;/h2&gt;
&lt;p&gt;Server-side Javascript (identified with the extension .jsm) is one of the two languages used to implement server side [[Scripting|scripts]] used by scripted customizations. Server-side Javascript is an implementation of the &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;ECMAScript 5.1&lt;/a&gt; specification with access to the full Verint Community Widget/Scripting API. Javascript, and specifically Server-side Javascript, is best suited for processing of data whereas [[Using Velocity|Velocity]] is better suited for text formatting.&lt;/p&gt;
&lt;p&gt;Within a scripted customization, the scripted customization itself is executed within its own local scope with platform APIs exposed via the global scope. This means the Javascript concept &amp;quot;this&amp;quot; refers to the scripted component entry point (the current execution of the widget&amp;#39;s content script or the current execution of the theme&amp;#39;s body script, for example).&lt;/p&gt;
&lt;h2&gt;&lt;a id="Server-side_Javascript_Syntax" name="Server-side_Javascript_Syntax"&gt;&lt;/a&gt;Server-side Javascript Syntax&lt;/h2&gt;
&lt;p&gt;Server-side Javascript is a full implementation of the ECMAScript 5.1 specification. &lt;a href="https://www.ecma-international.org/ecma-262/5.1/"&gt;Language details for ECMAScript 5.1 can be found here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Widget_Extension_Usage_in_Server-side_Javascript" name="Widget_Extension_Usage_in_Server-side_Javascript"&gt;&lt;/a&gt;Widget Extension Usage in Server-side Javascript&lt;/h2&gt;
&lt;p&gt;Most of the Platform API is available to Server-side Javascript, implemented as a set of widget extensions automatically available in the context of an executed Server-side Javascript script.&lt;/p&gt;
&lt;p&gt;For more information, please refer to the full set of [[Widget Extensions]].&lt;/p&gt;
&lt;h3&gt;&lt;a id="Example_Widget_Extension_Usage" name="Example_Widget_Extension_Usage"&gt;&lt;/a&gt;Example Widget Extension Usage&lt;/h3&gt;
&lt;p&gt;The following example will retrieve and render a list of blog posts in the current blog&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;// Retrieve the current blog. If there is none, hide the widget
var currentBlog = core_v2_blog.Current;
if (!currentBlog)
	return &amp;#39;&amp;#39;;

// Store the result in an array that we&amp;#39;ll later join to form
// the response string.
var resultHtml = [];

// Retrieve the 5 latest blog posts
var blogPosts = core_v2_blogPost.List({ 
    BlogId: currentBlog.Id, 
    PageSize: 5 
    });

if (blogPosts.Count &amp;gt; 0) {
    resultHtml.push(&amp;#39;&amp;lt;ul&amp;gt;&amp;#39;);
    for (var i = 0; i &amp;lt; blogPosts.Count; i++) {
        resultHtml.push(&amp;#39;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;&amp;#39;);
        resultHtml.push(core_v2_encoding.HtmlAttributeEncode(blogPosts[i].Url));
        resultHtml.push(&amp;#39;&amp;quot;&amp;gt;&amp;#39;);
        resultHtml.push(blogPosts[i].Title);
        resultHtml.push(&amp;#39;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;#39;);
    }
    resultHtml.push(&amp;#39;&amp;lt;/ul&amp;gt;&amp;#39;);
} else {
    resultHtml.push(&amp;#39;&amp;lt;span class=&amp;quot;message&amp;quot;&amp;gt;No blog posts&amp;lt;/span&amp;gt;&amp;#39;);
}

// Combine the array of HTML fragments and return it
return resultHtml.join(&amp;#39;\n&amp;#39;);&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Tips_and_Tricks" name="Tips_and_Tricks"&gt;&lt;/a&gt;Tips and Tricks&lt;/h2&gt;
&lt;h3&gt;&lt;a id="Remember_to_return" name="Remember_to_return"&gt;&lt;/a&gt;Remember to return&lt;/h3&gt;
&lt;p&gt;The result of rendering Server-side Javascript is provided via the &lt;code&gt;return&lt;/code&gt; statement which can occur anywhere within the script&amp;#39;s implementation. If implementing a widget or theme script using Server-side Javascript, be sure to&amp;nbsp;provide the result of the rendering using &lt;code&gt;return&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;a id="You_can_return_other_types" name="You_can_return_other_types"&gt;&lt;/a&gt;You can return other types&lt;/h3&gt;
&lt;p&gt;When executing a Server-side Javascript script from another script (even from [[Using Velocity|Velocity]]) using &lt;code&gt;core_v2_widget.ExecuteFile()&lt;/code&gt;, the Server-side Javascript can return a Javascript object containing multiple values and even functions with contextual state. You can effectively create a custom scripting API by returning a complex object from an executed Server-side Javascript.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Built-in_JSON_formatting" name="Built-in_JSON_formatting"&gt;&lt;/a&gt;Built-in JSON formatting&lt;/h3&gt;
&lt;p&gt;TBD&lt;/p&gt;
&lt;h3&gt;&lt;a id="Working_with_API_Lists" name="Working_with_API_Lists"&gt;&lt;/a&gt;Working with API Lists&lt;/h3&gt;
&lt;p&gt;Lists of results from API calls are not Javascript arrays so Javascript array functions and the &lt;code&gt;.length&lt;/code&gt; property are not available. Refer to the inline documentation for the API that you&amp;#39;re using and details about its return type, but, in general, remember to use &lt;code&gt;.Count&lt;/code&gt; instead of &lt;code&gt;.length&lt;/code&gt; for API list results.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Using Server-side Javascript</title><link>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript/revision/1</link><pubDate>Fri, 21 Jun 2019 19:35:15 GMT</pubDate><guid isPermaLink="false">22836c74-6c77-4a15-97b1-a26123ce5aa7</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65595/using-server-side-javascript#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/21/2019 19:35:15&lt;br /&gt;
&lt;p&gt;TBD&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>