Tuesday, February 25, 2014

How to get Query String parameters from JavaScript


We can easily set up a Javascript function that will retrieve the query string and load an array with the values passed in the query string. Here it is. This function goes into the head section of our page.

var qsParm;
        GetQueryStringParams();

        function GetQueryStringParams() {
            //Holds key:value pairs
            qsParm = new Array();
            //Get querystring from url
            var requestUrl = window.location.search.toString();
            if (requestUrl != '') {
                //window.location.search returns the part of the URL
                //that follows the ? symbol, including the ? symbol
                var query = requestUrl.substring(1);

                //Get key:value pairs from querystring
                var parms = query.split('&');

                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0) {
                        var key = parms[i].substring(0, pos);
                        var val = parms[i].substring(pos + 1);
                        qsParm[key] = val;
                    }
                }
            }
        }

MS CRM 4.0/2011 : How to get more than 5000 record from CRM database.

Sometimes you required to retrieve all the entity record from database using FETCH and QUERY EXPRESSION but CRM limitation to not retrieve more than 5000 records. The way to retrieve use the below line of code:

public static List<DynamicEntity> GetAllEntityRecords(CrmService service, string entityName, List<ConditionExpression> conditions, ColumnSet columns)
        {
            List<DynamicEntity> records = null;
            try
            {
                QueryExpression query = new QueryExpression();
                query.EntityName = entityName;

                if (columns != null)
                    query.ColumnSet = columns;
                else
                    query.ColumnSet = new AllColumns();

                if (conditions != null && conditions.Any())
                {
                    query.Criteria = new FilterExpression();
                    query.Criteria.FilterOperator = LogicalOperator.And;

                    foreach (var cond in conditions)
                    {
                        query.Criteria.AddCondition(cond);
                    }
                }
                query.PageInfo = new PagingInfo();
                query.PageInfo.Count = 100;
                query.PageInfo.PageNumber = 1;
                query.PageInfo.PagingCookie = null;

                RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
                retrieve.Query = query;
                retrieve.ReturnDynamicEntities = true;

                records = new List<DynamicEntity>();

                while (true)
                {

                    BusinessEntityCollection results = ((RetrieveMultipleResponse)service.Execute(retrieve)).BusinessEntityCollection;
                    if (results.BusinessEntities != null)
                    {
                        foreach (DynamicEntity de in results.BusinessEntities)
                            records.Add(de);
                    }

                    // Check for morerecords, if it returns true.
                    if (results.MoreRecords)
                    {
                        // Increment the page number to retrieve the next page.
                        query.PageInfo.PageNumber++;
                        // Set the paging cookie to the paging cookie returned from current results.
                        query.PageInfo.PagingCookie = results.PagingCookie;
                    }
                    else
                    {
                        // If no more records are in the result nodes, exit the loop.
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return records;
        }

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...