private void BuildGrid(string logicalName)
        {
            gridMap.DataSource          = null;
            gridMap.AutoGenerateColumns = false;
            if (tabSample.Parent == tabGrpMain)
            {
                tabGrpHidden.TabPages.Add(tabSample);
            }

            List <string> mapsNotFound      = new List <string>();
            string        primaryFieldLabel = "Primary Name Column: ";
            var           saveMap           = cboSelectSaved.SelectedItem == null ? null : mySettings.Settings.First(stng => stng.Name == cboSelectSaved.SelectedItem.ToString());

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Retrieving Attributes...",
                Work    = (w, e) =>
                {
                    var entityMeta     = Service.GetEntityMetadata(logicalName);// entitiesDD.SelectedEntity.LogicalName);
                    var primaryField   = entityMeta.Attributes.First(at => at.LogicalName == entityMeta.PrimaryNameAttribute) as StringAttributeMetadata;
                    primaryFieldLabel += primaryField.DisplayName.UserLocalizedLabel == null ? primaryField.LogicalName : primaryField.DisplayName.UserLocalizedLabel.Label + " ( " + primaryField.LogicalName + " ) ";
                    if (!string.IsNullOrEmpty(primaryField.FormulaDefinition))
                    {
                        primaryFieldLabel += " Formula: " + primaryField.FormulaDefinition;
                    }

                    SortableBindingList <MapRow> attributes = new SortableBindingList <MapRow>();
                    w.ReportProgress(50, "Got Attributes");
                    foreach (var field in entityMeta.Attributes.Where(fld => !notPermitted.Any(np => np == fld.AttributeType)).Where(fld => fld.IsValidForCreate == true &&
                                                                                                                                     (!mySettings.ExcludeConfig.ImportSeqNo || fld.LogicalName != "importsequencenumber") &&
                                                                                                                                     (mySettings.ExcludeConfig.DeprecatedColumns ? (!fld.DisplayName.LocalizedLabels.Any() || fld.DisplayName.LocalizedLabels.Any(lbl => !lbl.Label.ToLower().Contains("deprecated"))) : true)
                                                                                                                                     ))
                    {
                        var mapRow              = new MapRow(field);
                        mapRow.PropertyChanged += MapRow_PropertyChanged;

                        attributes.Add(mapRow);
                    }

                    w.ReportProgress(100, "Loading Grid");
                    e.Result = attributes;
                },
                ProgressChanged  = e => SetWorkingMessage(e.UserState.ToString()),
                PostWorkCallBack = e =>
                {
                    gridMap.DataSource = e.Result;
                    SetUpColumns();
                    //ColourPrimaryNameField(e.Result as SortableBindingList<MapRow>);
                    lblPrimary.Text = primaryFieldLabel;
                    LogInfo(DateTime.UtcNow + " |  Start with SavedMaps");
                    if (saveMap != null)
                    {
                        var attributes = gridMap.DataSource as SortableBindingList <MapRow>;
                        foreach (var map in saveMap.MapRows)
                        {
                            if (attributes.Any(mr => mr.AttributeName == map.AttributeName))
                            {
                                // #5 If no mocks in the save, don't bother doing anything
                                if (map.SelectedMock.Count > 0)
                                {
                                    var mapRow = attributes.First(mr => mr.AttributeName == map.AttributeName);
                                    AddOptions(mapRow);
                                    var mockType   = map.SelectedMock.First(kvp => kvp.Key == "MockName").Value.ToString();
                                    var mockOption = mapRow.MockOptions.Mocks.FirstOrDefault(m => m.Name == mockType);
                                    if (mockOption != null)
                                    {
                                        selectedMaps.Add(mapRow);
                                        mapRow.PropertyChanged -= MapRow_PropertyChanged;
                                        LogInfo(DateTime.UtcNow + " |  Pre Select Change");
                                        mapRow.Selected = true;
                                        LogInfo(DateTime.UtcNow + " |  Pre mocktype change");

                                        mapRow.MockType = mockType;

                                        mapRow.SelectedMock = mockOption.Clone();
                                        LogInfo(DateTime.UtcNow + " |  Pre KVPPopulate");
                                        Populate(mapRow.Attribute, mapRow.SelectedMock, true);
                                        //PopulateLookup(mapRow.Attribute, mapRow.SelectedMock);
                                        //PopulatePickList(mapRow.Attribute, mapRow.SelectedMock);
                                        //PopulateSet(mapRow.Attribute, mapRow.SelectedMock);

                                        mapRow.SelectedMock.PopulateFromKVP(map.SelectedMock);
                                        LogInfo(DateTime.UtcNow + " | post KVPPopulate");

                                        gridMap.Rows.Cast <DataGridViewRow>().Where(mr => mr.DataBoundItem == mapRow).First().Cells["Config"].ReadOnly
                                            = mapRow.AdditionalProperties == string.Empty;
                                        gridMap.Rows.Cast <DataGridViewRow>().Where(mr => mr.DataBoundItem == mapRow).First().Cells[percBlank].ReadOnly
                                            = mapRow.SelectedMock.Fixed;

                                        //SetUpNumberDefaults(mapRow.Attribute, mapRow.SelectedMock);
                                        mapRow.PropertyChanged += MapRow_PropertyChanged;
                                    }
                                }
                            }
                            else
                            {
                                mapsNotFound.Add(map.AttributeName);
                            }
                        }
                    }

                    if (mapsNotFound.Count > 0)
                    {
                        MessageBox.Show("These attributes could not be found\r\n" + string.Join("\r\n", mapsNotFound.ToArray()) + "\r\nPlease ensure mapping still valid", "Not all maps found", MessageBoxButtons.OK);
                    }
                    gridMap.AutoResizeColumns();
                    gridMap.Sort(gridMap.Columns[1], ListSortDirection.Ascending);
                    LogInfo(DateTime.UtcNow + " |  Ended with SavedMaps");
                }
            });
        }