Wednesday, March 27, 2013

CRM 2011-Run Report from Ribbon button


   1.  Create a new  web resource (javascipt) with following code
        
            function printOutOnClick(rdlName,reportGuid,entityGuid,entityType)
               {
                   var serverUrl = Xrm.Page.context.getServerUrl();
   
             var link = serverUrl + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=" + rdlName  + "&id={" + reportGuid + "}&records=" + entityGuid + "&recordstype=" + entityType;
   window.open(link);
         }
.   2.Create a new button using visual ribbon editor and pass parameter  as follows

Function Name: printOutOnClick
Library: $webresource:<created web resource name>
1. String parameter Value: <Name of report file> ("somereport.rdl")
2.String parameter Value: < Id of Report >
3.Crm parameter: FirstPrimaryItemId //to pass current record id
4.Crm parameter: PrimaryEntitytypeCode //to pass entity code.

Friday, March 22, 2013

CRM 2011-Silverlight Retrieve Multiple query

   public static void LoadProducts(string txt)
            {
            try
                {
                DataServiceQuery<Product> query = (DataServiceQuery<Product>)context.ProductSet.Where<Product>(a => a.ProductNumber.StartsWith(txt) );
                query.BeginExecute(OnReapirGunModelComplete1, query);
                }
            catch (Exception ex)
                {
                _syncContext.Send(new SendOrPostCallback(showErrorDetails), ex);
                }
            }
        private static void OnReapirGunModelComplete1(IAsyncResult result)
            {
            try
                {
                DataServiceQuery<Product> results = result.AsyncState as DataServiceQuery<Product>;
                List<Product> tmp = new DataServiceCollection<Product>(results.EndExecute(result)).ToList<Product>();
                if (tmp.Count > 0)
                    {
                   //your code
                    }
                }
            catch (Exception ex)
                {
                _syncContext.Send(new SendOrPostCallback(showErrorDetails), ex);
                }
            }