Removing added new line break after using SSI with Charset UTF-8 in Visual Studio or Notepad++

When using SSI in your HTML page with charset=”UTF-8″  the new line will be added after each time you use includes. it’s because your file encoding is saved with BOM or signature.

In order to overcome this, if you are using Visual Studio go to:  file> Advanced Saved Options  and change the Encoding to  UTF-8(Unicode without signature).

If you use Notepad++ go to: Encoding > Encode in UTF-8 Without BOM you should save all your Include files(.inc) to remove that extra space happen.

Merging Entities in Dynamics CRM using Webservices and MergeRequest

If you have lots of duplicated accounts in you system that has lots of records like Orders or Invoices under them, you can use MergeRequest to merge those accounts.

The good thing about merge is that it will handle all relationships for you and you don’t have to worry about related order or invoices ,etc. you also define what fields you want to copy from duplicated record to main record.

Here is a sample code for merging all duplicated accounts in CRM:

I retrieve all accounts in CRM where their account number contains “-0” and then based on that criteria retrieved the duplicated.

If you have more than 5000 records , the Retrieve Multiple will only return first 5000 records so it’s better to use “ConditionOperator” to restrict the number of accounts to be retrieved in your QueryExpression. I find it really useful and fast. Use  “ConditionOperator.Like“…

private void btnMerge_Click(object sender, EventArgs e)
        {
            //connecting to the service and getting the credentials from app.confi
            ClientCredentials Credentials = new ClientCredentials();
            ClientCredentials oClientCredential = new ClientCredentials();
            oClientCredential.UserName.UserName = System.Configuration.ConfigurationManager.AppSettings["userName"];
            oClientCredential.UserName.Password = System.Configuration.ConfigurationManager.AppSettings["password"];

            Uri OrganizationUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["CRMURI"]);
            Uri HomeRealmUri = null;

            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, oClientCredential, null))
            {
                try
                {
                    IOrganizationService service = (IOrganizationService)serviceProxy;

                    QueryExpression query = new QueryExpression();

                    query.EntityName = "account";

                    query.ColumnSet = new ColumnSet() { AllColumns = true };

                    query.Criteria = new FilterExpression();

                    query.Criteria.FilterOperator = LogicalOperator.And;

                    query.Criteria.Conditions.Add

                    (
                     new ConditionExpression("statuscode", ConditionOperator.Equal, 1)//all the active accounts
                    );

                    query.Criteria.Conditions.Add(new ConditionExpression("accountnumber", ConditionOperator.Like, "%-0%"));

                    EntityCollection entities = service.RetrieveMultiple(query);

                    //loop through the list of retrieved entities and find the duplicate that match the criteria 

                    foreach (var item in entities.Entities)
                    {
                        string accountNumber = item.GetAttributeValue<string>("accountnumber").ToString();
                        string mainAccountNumber = item.GetAttributeValue<string>("dtm_mainaccountnumber").ToString();
                        string accountName = item.GetAttributeValue<string>("name").ToString();

                        if (accountNumber.Contains("-0"))
                        {
                            int start = accountNumber.IndexOf('-');
                            string strAdressCode = accountNumber.Substring(start + 1, accountNumber.Length - start - 1);
                            int number;
                            if (Int32.TryParse(strAdressCode, out number))
                            {
                                EntityReference target = new EntityReference();
                                target.Id = item.Id;
                                target.LogicalName = "account";

                                string newAccountNumber = accountNumber.Substring(0, start + 1) + number;

                                QueryExpression innerQuery = new QueryExpression();
                                innerQuery.EntityName = "account";
                                innerQuery.ColumnSet = new ColumnSet() { AllColumns = true };
                                innerQuery.Criteria = new FilterExpression();
                                innerQuery.Criteria.FilterOperator = LogicalOperator.And;
                                innerQuery.Criteria.Conditions.Add(new ConditionExpression("statuscode", ConditionOperator.Equal, 1));
                                innerQuery.Criteria.Conditions.Add(new ConditionExpression("dtm_mainaccountnumber", ConditionOperator.Equal, mainAccountNumber));
                                //innerQuery.Criteria.Conditions.Add(new ConditionExpression("name", ConditionOperator.Equal, accountName));
                                innerQuery.Criteria.Conditions.Add(new ConditionExpression("accountnumber", ConditionOperator.Equal, newAccountNumber));

                                EntityCollection innerEntities = service.RetrieveMultiple(innerQuery);

                                if (innerEntities.Entities.Count >= 1)
                                {

                                    // Create the request for Merge
                                    MergeRequest merge = new MergeRequest();
                                    merge.SubordinateId = innerEntities.Entities[0].Id;
                                    merge.Target = target;
                                    merge.PerformParentingChecks = false;
                                    
                                    // Create another account to hold new data to merge into the entity.
                                    // If you use the subordinate account object, its data will be merged.
                                    Entity updateContent = new Entity("account");
                                    updateContent["dtm_ismerged"] = "merged";

                                    // Set the content you want updated on the merged account
                                    merge.UpdateContent = updateContent;

                                    service.Execute(merge);
                                }
                            }
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                    string fileloc = "C:\\myLog.txt";

                    if (File.Exists(fileloc))
                    {
                        using (StreamWriter sw = new StreamWriter(fileloc))
                        {
                            sw.Write(ex.ToString());
                        }
                    }

                }
            }
        }

Inventory Available to Promise (ATP) in Microsoft Dynamics GP

The Inventory Available to Promise screen will give you insight into your current inventory situation for any item. For any item that you select in this screen you will see the supply and demand for the item in a time sorted list. You can drill back into any listed item to get more information.

This feature of Dynamics GP will empower your employees with the knowledge they need to make and keep firm delivery promises.It delivers fast access to vital inventory information—including current and future positions—to help you make effective use of inventory, improve service, and maximize profitability.

ATP

 

Using this query from your GP database you can get ATP quantity for specific site in your organization:

SELECT [Item Number]
,[QTY In Use]
,[QTY In Service]
,[QTY Returned]
,[Location Code]
,[Record Type]
,[QTY On Order]
,[QTY On Hand]
,[QTY Allocated]
,[QTY Available]
,[Item Description]
,[QTY Damaged]
,[QTY On Order from Vendor Item]
,[QTY Sold]
,[U Of M Schedule]
,[U Of M Schedule Description]
,[Location Code]
FROM [<em>YourSchema</em>].[dbo].[ItemQuantities]
WHERE [Location Code]=<em>’your site location code’</em>
ORDER BY [QTY Available] desc