Thursday, July 5, 2012

Passing parameters to a Web Resource(javascript/html) Through the Data Parameter

Passing CRM parameters in Silverlight or to Get the cuurent record id in silverlight






 
        public static string OrgName;
        public static string EntityName;
        public static Guid RecordId;

         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             IDictionary<string, string> QueryString = HtmlPage.Document.QueryString;
             if (QueryString.ContainsKey("orgname"))
                 OrgName = QueryString["orgname"];
           
             if (QueryString.ContainsKey("typename"))
                 EntityName = QueryString["typename"];

             if (QueryString.ContainsKey("id"))
               RecordId =new Guid(QueryString["id"]);

         }

to Get the cuurent record id in silverlight

Guid currentRecordId=new Guid();
//Keeps a reference to the UI thread
_syncContext =
SynchronizationContext.Current;
 
//Get the ServerUrl (ServerUrl is formatted differently OnPremise than OnLine)
_serverUrl =
ServerUtility.GetServerUrl();
if (!String.IsNullOrEmpty(_serverUrl))
{
//Setup Context
_context =
new ccaContext(
new Uri(String.Format("{0}/xrmservices/2011/organizationdata.svc/",
_serverUrl),
UriKind.Absolute));
//This is important because if the entity has new
//attributes added the code will fail.
_context.IgnoreMissingProperties =
true;
IDictionary<string, string> QueryString = HtmlPage.Document.QueryString;
if (QueryString.ContainsKey("id"))
{
currentRecordId =
new Guid(QueryString["id"]);
}
}
else
{
//No ServerUrl was found. Display message.
MessageBox.Show(
"Unable to access server url. Launch this Silverlight " +
"Web Resource from a CRM Form OR host it in a valid " +
"HTML Web Resource with a " +
"<script src='../ClientGlobalContext.js.aspx' " +
"type='text/javascript'></script>"
);
}

 
 for more details,click here: