I am storing some details from my tridion pages in the APP_DATA table by passing it on to the DATA_CONTENT column as a stream. While retrieving it via a service call method, the values are not getting displayed on the page although it is present in the DB.
Here's how I retrieve the details:
if ($url.getHashParam("id") != null) // We want to pull app data only for existing pages
{
if ($url.getHashParam("id").indexOf("-64") != -1)
window.onload = $modelUtils.getAppData($url.getHashParam("id"), Namespace.Methods.handleGetAppData);
}
This getAppData
method is defined in another JS file as below:
Type.registerNamespace("Namespace");
Namespace.Utilities = function () {
};
Namespace.Utilities.getAppData = function (pageID, handler) {
try {
var onError = null;
var context = null;
Namespace.GetAppData(pageID,
handler,
onError,
context,
false);
}
catch (err) {
$messages.registerWarning('Unable to execute GetAppData WCF service Process.', '', false);
}
}
And again GetAppData
is a service call method which goes as:
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string GetAppData(string pageID)
{
try {
return GetAppDataFromPage(pageID);
}
catch (Exception ex) {
throw ex;
}
finally {
if (channel != null && channel.State != CommunicationState.Closed)
{
channel.Close();
}
}
}
public string GetAppDataFromPage(string pageID)
{
using (Session adminSession = new Session("NT AUTHORITY\\SYSTEM"))
{
Page p = new Page(new TcmUri(pageID), adminSession);
IEnumerable<Tridion.ContentManager.ApplicationData> appData = p.LoadAllApplicationData();
uint uIntVersion = (uint)((p.DynamicVersion.Revision > 0) ? 0 : (p.Version));
VersionedItem majVersion = p.GetVersion(uIntVersion);
Tridion.ContentManager.ApplicationData applicationData = majVersion.LoadApplicationData("APP_ID_NAME");
if (applicationData != null)
return System.Text.Encoding.Unicode.GetString(applicationData.Data);
}
return string.Empty;
}