<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communitytest.tessitura.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Show Information from a Custom Data Service</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/805/show-information-from-a-custom-data-service</link><description>Wiki for creating community documentation.</description><dc:language>en-US</dc:language><generator>Telligent Community 12 Non-Production</generator><item><title>Show Information from a Custom Data Service</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/805/show-information-from-a-custom-data-service</link><pubDate>Wed, 08 Mar 2023 16:30:53 GMT</pubDate><guid isPermaLink="false">fd08b0f2-65fa-4b2b-916a-cce3e88b61d0:5d88c84d-819d-4c22-be71-2c11f8342a72</guid><dc:creator>John A. Moskal II</dc:creator><comments>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/805/show-information-from-a-custom-data-service#comments</comments><description>Current Revision posted to Community Docs Wiki by John A. Moskal II on 3/8/2023 4:30:53 PM&lt;br /&gt;
&lt;p&gt;This is an example of fetching and displaying in an HTML Template e-mail, arbitrary data from a custom Data Service Table/View stored in &lt;span style="font-family:courier new, courier;"&gt;TR_DATASERVICE_TABLES&lt;/span&gt;.&amp;nbsp; Updates/edits welcome.&lt;/p&gt;
&lt;p&gt;In this example, we reference a local database view &lt;span style="font-family:courier new, courier;"&gt;LVXS_CP_ORDER_PRIMARY_ORG&lt;/span&gt; with the name &lt;span style="font-family:courier new, courier;"&gt;CPOrdersPrimaryOrg&lt;/span&gt; and unique key column of &lt;span style="font-family:courier new, courier;"&gt;order_no&lt;/span&gt;.&amp;nbsp; Sample reason this might be needed is in a consortium environment where orders might feature products from multiple organizations and there is a need to determine a primary/joint style/content template for the e-mail.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="html"&gt;@* Sample get single custom dataservice element based on ID *@

@* Use Newtonsoft.Json for parsing *@
@using Newtonsoft.Json;
@using Tessitura.Services.Common.Client.Utils;

@* Define object CPOrderOrg for properly named and typed results *@
@functions
{       
    public class CPOrderOrg
    {
        [JsonPropertyAttribute(&amp;quot;organization&amp;quot;)]
        public int OrgId;
        [JsonPropertyAttribute(&amp;quot;org_desc&amp;quot;)]
        public string OrgDesc;
    }
}

@* Define URL for and get data from custom dataservice entry CPOrdersPrimaryOrg based on the Order ID; single object results *@
@{
    @* Order ID is provided in the Order Confirmations template type *@
    var customURL = &amp;quot;Custom/CPOrdersPrimaryOrg/&amp;quot; + Model.OrderProductView.Id;
    var orderPrimaryOrg = Model.RestClient
        .AtUrl(customURL)
        .WithContentType(ContentType.Json)
        .Get&amp;lt;CPOrderOrg&amp;gt;()
        .ResponseObject;
}

@* Output results *@
&amp;lt;p&amp;gt;
    @orderPrimaryOrg.OrgId
    @orderPrimaryOrg.OrgDesc
&amp;lt;/p&amp;gt;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: HTML Templates, razor, REST API&lt;/div&gt;
</description></item><item><title>Show Information from a Custom Data Service</title><link>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/805/show-information-from-a-custom-data-service/revision/1</link><pubDate>Wed, 08 Mar 2023 16:29:45 GMT</pubDate><guid isPermaLink="false">fd08b0f2-65fa-4b2b-916a-cce3e88b61d0:5d88c84d-819d-4c22-be71-2c11f8342a72</guid><dc:creator>John A. Moskal II</dc:creator><comments>https://communitytest.tessitura.com/topical_groups/developers/w/community-developer-documentation/805/show-information-from-a-custom-data-service#comments</comments><description>Revision 1 posted to Community Docs Wiki by John A. Moskal II on 3/8/2023 4:29:45 PM&lt;br /&gt;
&lt;p&gt;This is an example of fetching and displaying in an HTML Template e-mail, arbitrary data from a custom Data Service Table/View stored in &lt;span style="font-family:courier new, courier;"&gt;TR_DATASERVICE_TABLES&lt;/span&gt;.&amp;nbsp; Updates/edits welcome.&lt;/p&gt;
&lt;p&gt;In this example, we reference a local database view &lt;span style="font-family:courier new, courier;"&gt;LVXS_CP_ORDER_PRIMARY_ORG&lt;/span&gt; with the name &lt;span style="font-family:courier new, courier;"&gt;CPOrdersPrimaryOrg&lt;/span&gt; and unique key column of &lt;span style="font-family:courier new, courier;"&gt;order_no&lt;/span&gt;.&amp;nbsp; Sample reason this might be needed is in a consortium environment where orders might feature products from multiple organizations and there is a need to determine a primary/joint style/content template for the e-mail.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;@* Sample get single custom dataservice element based on ID *@

@* Use Newtonsoft.Json for parsing *@
@using Newtonsoft.Json;
@using Tessitura.Services.Common.Client.Utils;

@* Define object CPOrderOrg for properly named and typed results *@
@functions
{       
    public class CPOrderOrg
    {
        [JsonPropertyAttribute(&amp;quot;organization&amp;quot;)]
        public int OrgId;
        [JsonPropertyAttribute(&amp;quot;org_desc&amp;quot;)]
        public string OrgDesc;
    }
}

@* Define URL for and get data from custom dataservice entry CPOrdersPrimaryOrg based on the Order ID; single object results *@
@{
    @* Order ID is provided in the Order Confirmations template type *@
    var customURL = &amp;quot;Custom/CPOrdersPrimaryOrg/&amp;quot; + Model.OrderProductView.Id;
    var orderPrimaryOrg = Model.RestClient
        .AtUrl(customURL)
        .WithContentType(ContentType.Json)
        .Get&amp;lt;CPOrderOrg&amp;gt;()
        .ResponseObject;
}

@* Output results *@
&amp;lt;p&amp;gt;
    @orderPrimaryOrg.OrgId
    @orderPrimaryOrg.OrgDesc
&amp;lt;/p&amp;gt;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: HTML Templates, razor, REST API&lt;/div&gt;
</description></item></channel></rss>