示例#1
0
        public bool IsIncludeField(string fieldName, string entityType)
        {
            var hardcodeInvalidFields = HardcodedIgnoreFields;

            if (hardcodeInvalidFields.Contains(fieldName))
            {
                return(false);
            }
            //these are just hack since they are not updateable fields (IsWriteable)
            if (fieldName == "parentbusinessunitid")
            {
                return(true);
            }
            if (fieldName == "businessunitid")
            {
                return(true);
            }
            if (fieldName == "pricelevelid")
            {
                return(true);
            }
            if (fieldName == "salesliteratureid")
            {
                return(true);
            }
            return
                (XrmRecordService.FieldExists(fieldName, entityType) && XrmRecordService.GetFieldMetadata(fieldName, entityType).Writeable);
        }
示例#2
0
        public static bool IsIncludeField(string fieldName, string entityType, XrmRecordService xrmRecordService, bool includeOwner)
        {
            var hardcodeInvalidFields = GetIgnoreFields(entityType, includeOwner);

            if (hardcodeInvalidFields.Contains(fieldName))
            {
                return(false);
            }
            //these are just hack since they are not updateable fields (IsWriteable)
            if (fieldName == "parentbusinessunitid")
            {
                return(true);
            }
            if (fieldName == "businessunitid")
            {
                return(true);
            }
            if (fieldName == "pricelevelid")
            {
                return(true);
            }
            if (fieldName == "salesliteratureid")
            {
                return(true);
            }
            if (fieldName == "transactioncurrencyid")
            {
                return(true);
            }
            if (fieldName == "salesliteratureid")
            {
                return(true);
            }
            if (entityType == Entities.productsubstitute &&
                new [] { Fields.productsubstitute_.productid, Fields.productsubstitute_.substitutedproductid }.Contains(fieldName))
            {
                return(true);
            }
            if (fieldName == Fields.product_.productstructure)
            {
                return(true);
            }
            return
                (xrmRecordService.FieldExists(fieldName, entityType) && xrmRecordService.GetFieldMetadata(fieldName, entityType).Writeable);
        }
        private void VerifyFields(CustomisationImportRequest request)
        {
            var response = new CustomisationImportResponse();

            var optionMetadata =
                CustomisationImportService.ExtractOptionSetsFromExcel(request.ExcelFile.FileName, Controller, response);
            var fieldMetadata =
                CustomisationImportService.ExtractFieldMetadataFromExcel(request.ExcelFile.FileName, Controller,
                                                                         optionMetadata, response).Values;

            foreach (var field in fieldMetadata)
            {
                Assert.IsTrue(XrmRecordService.FieldExists(field.SchemaName, field.RecordType));
                Assert.IsTrue(XrmRecordService.GetFieldLabel(field.SchemaName, field.RecordType) ==
                              field.DisplayName);
                Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).Description ==
                              field.Description);
                Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).IsMandatory ==
                              field.IsMandatory);
                Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).Audit ==
                              field.Audit);
                Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).Searchable ==
                              field.Searchable);
                if (field.FieldType == RecordFieldType.String)
                {
                    Assert.IsTrue(XrmRecordService.GetMaxLength(field.SchemaName, field.RecordType) ==
                                  ((StringFieldMetadata)field).MaxLength);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).TextFormat ==
                                  ((StringFieldMetadata)field).TextFormat);
                }
                if (field.FieldType == RecordFieldType.Integer)
                {
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MinValue ==
                                  ((IntegerFieldMetadata)field).MinValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MaxValue ==
                                  ((IntegerFieldMetadata)field).MaxValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).IntegerFormat ==
                                  ((IntegerFieldMetadata)field).IntegerFormat);
                }
                if (field.FieldType == RecordFieldType.Decimal)
                {
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MinValue ==
                                  ((DecimalFieldMetadata)field).MinValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MaxValue ==
                                  ((DecimalFieldMetadata)field).MaxValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).DecimalPrecision ==
                                  ((DecimalFieldMetadata)field).DecimalPrecision);
                }
                if (field.FieldType == RecordFieldType.Date)
                {
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).IncludeTime ==
                                  ((DateFieldMetadata)field).IncludeTime);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).DateBehaviour ==
                                  ((DateFieldMetadata)field).DateBehaviour);
                }
                if (field.FieldType == RecordFieldType.Picklist)
                {
                    var actualOptions = XrmRecordService.GetPicklistKeyValues(field.SchemaName,
                                                                              field.RecordType);
                    var expectedOption = ((PicklistFieldMetadata)field).PicklistOptions;
                    VerifyOptionSetsEqual(actualOptions, expectedOption);
                    Assert.AreEqual(field.IsMultiSelect, XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).IsMultiSelect);
                }
                if (field.FieldType == RecordFieldType.Double)
                {
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MinValue ==
                                  ((DoubleFieldMetadata)field).MinValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).MaxValue ==
                                  ((DoubleFieldMetadata)field).MaxValue);
                    Assert.IsTrue(XrmRecordService.GetFieldMetadata(field.SchemaName, field.RecordType).DecimalPrecision ==
                                  ((DoubleFieldMetadata)field).DecimalPrecision);
                }
            }
        }
        public void DeploymentExportXmlModuleTestExportWithBulkAddToGridAndQuery()
        {
            DeleteAll(Entities.account);

            var account = CreateRecordAllFieldsPopulated(Entities.account);

            FileUtility.DeleteFiles(TestingFolder);

            var accountRecord = XrmRecordService.Get(account.LogicalName, account.Id.ToString());

            //okay create/navigate to a new entry form entering an ExportXmlRequest
            var application = CreateAndLoadTestApplication <ExportXmlModule>();
            var instance    = new ExportXmlRequest();

            instance.IncludeNotes = true;
            instance.IncludeNNRelationshipsBetweenEntities = true;
            instance.Folder = new Folder(TestingFolder);
            instance.RecordTypesToExport = new[]
            {
                new ExportRecordType()
                {
                    Type       = ExportType.SpecificRecords,
                    RecordType = new RecordType(Entities.account, Entities.account),
                    SpecificRecordsToExport = new [] { new LookupSetting()
                                                       {
                                                           Record = accountRecord.ToLookup()
                                                       } }
                }
            };
            var entryForm = application.NavigateToDialogModuleEntryForm <ExportXmlModule, ExportXmlDialog>();

            application.EnterObject(instance, entryForm);

            //get the record types subgrid
            var recordTypesGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport));
            var row             = recordTypesGrid.GridRecords.First();

            //edit the accounts export record row
            row.EditRow();
            var specificRecordEntry = entryForm.ChildForms.First() as RecordEntryFormViewModel;

            specificRecordEntry.LoadFormSections();
            var specificRecordsGrid = specificRecordEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.SpecificRecordsToExport));

            //delete the row we added
            specificRecordsGrid.GridRecords.First().DeleteRow();
            Assert.IsFalse(specificRecordsGrid.GridRecords.Any());

            //now add using the add multiple option
            var customFunction = specificRecordsGrid.DynamicGridViewModel.AddMultipleRowButton;

            customFunction.Invoke();
            var bulkAddForm = specificRecordEntry.ChildForms.First() as QueryViewModel;

            //verify a quickfind finds a record
            bulkAddForm.QuickFindText = account.GetStringField(Fields.account_.name);
            bulkAddForm.QuickFind();
            Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage);
            Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any());

            //now do an and query on every field in the entity and verify it works
            bulkAddForm.QueryTypeButton.Invoke();

            var lastCondition = bulkAddForm.FilterConditions.Conditions.Last();

            Assert.AreEqual(Entities.account, lastCondition.GetRecordTypeFieldViewModel(nameof(ConditionViewModel.QueryCondition.RecordType)).Value.Key);
            var fieldViewModel = lastCondition.GetRecordFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.FieldName));

            var validSearchFields = fieldViewModel.ItemsSource
                                    .Select(i => i.Key)
                                    //lets just exclude non searchable fields here - some system ones e.g. opendeals_date don;t seem to work
                                    .Where(f => XrmRecordService.GetFieldMetadata(f, Entities.account).Searchable)
                                    .ToArray();

            foreach (var field in validSearchFields)
            {
                var fieldvalue = accountRecord.GetField(field);
                if (fieldvalue != null)
                {
                    lastCondition = bulkAddForm.FilterConditions.Conditions.Last();
                    Assert.AreEqual(Entities.account, lastCondition.GetRecordTypeFieldViewModel(nameof(ConditionViewModel.QueryCondition.RecordType)).Value.Key);
                    fieldViewModel       = lastCondition.GetRecordFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.FieldName));
                    fieldViewModel.Value = fieldViewModel.ItemsSource.ToArray().First(i => i.Key == field);
                    var conditionTypeViewModel = lastCondition.GetPicklistFieldFieldViewModel(nameof(ConditionViewModel.QueryCondition.ConditionType));
                    conditionTypeViewModel.Value = conditionTypeViewModel.ItemsSource.First(i => i.Value == ConditionType.Equal.ToString());
                    var valueViewModel = lastCondition.GetFieldViewModel(nameof(ConditionViewModel.QueryCondition.Value));
                    valueViewModel.ValueObject = fieldvalue;

                    //use this to break on a sepcific field which doesn;t work
                    bulkAddForm.QuickFind();
                    Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage);
                    Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any());
                }
            }


            bulkAddForm.QuickFind();
            Assert.IsFalse(bulkAddForm.DynamicGridViewModel.GridLoadError, bulkAddForm.DynamicGridViewModel.ErrorMessage);
            Assert.IsTrue(bulkAddForm.DynamicGridViewModel.GridRecords.Any());
            //select and add
            bulkAddForm.DynamicGridViewModel.GridRecords.First().IsSelected = true;
            //this triggered by the grid event
            bulkAddForm.DynamicGridViewModel.OnSelectionsChanged();
            //this is supposed to be the add selected button
            bulkAddForm.DynamicGridViewModel.CustomFunctions.Last().Invoke();

            //and verify the row was added to the records for export
            Assert.IsTrue(specificRecordsGrid.GridRecords.Any());

            //okay now lets do the equivalent for a grid of fields

            //set this false so the selection of fields is in context
            specificRecordEntry.GetBooleanFieldFieldViewModel(nameof(ExportRecordType.IncludeAllFields)).Value = false;

            //get the fields grid and trigger bulk add function
            var excludeFieldsGrid = specificRecordEntry.GetEnumerableFieldViewModel(nameof(ExportRecordType.IncludeOnlyTheseFields));

            //now add using the multi select dialog option
            excludeFieldsGrid.DynamicGridViewModel.AddMultipleRowButton.Invoke();

            var multiSelectForm = specificRecordEntry.ChildForms.First() as MultiSelectDialogViewModel <PicklistOption>;

            Assert.IsTrue(multiSelectForm.ItemsSource.Any());
            Assert.IsTrue(multiSelectForm.ItemsSource.First(i => i.PicklistItem.Key == Fields.account_.name).Select = true);
            multiSelectForm.ApplyButtonViewModel.Invoke();
            Assert.IsFalse(specificRecordEntry.ChildForms.Any());

            //and verify the row was added to the records for export
            Assert.IsTrue(excludeFieldsGrid.GridRecords.Any());

            specificRecordEntry.SaveButtonViewModel.Invoke();
            Assert.IsFalse(entryForm.ChildForms.Any());

            //okay now lets to bulk add on the record types grid
            var subGrid = entryForm.GetEnumerableFieldViewModel(nameof(ExportXmlRequest.RecordTypesToExport));

            subGrid.DynamicGridViewModel.AddMultipleRowButton.Invoke();

            multiSelectForm = entryForm.ChildForms.First() as MultiSelectDialogViewModel <PicklistOption>;
            Assert.IsTrue(multiSelectForm.ItemsSource.Any());
            Assert.IsTrue(multiSelectForm.ItemsSource.First(i => i.PicklistItem.Key == Entities.contact).Select = true);
            multiSelectForm.ApplyButtonViewModel.Invoke();
            Assert.IsFalse(entryForm.ChildForms.Any());
        }
示例#5
0
 private void ProcessForRelationships(CustomisationExporterRequest request,
                                      CustomisationExporterResponse response,
                                      LogController controller)
 {
     if (request.Relationships)
     {
         var allRelationship = new List <RelationshipExport>();
         var types           = GetRecordTypesToExport(request).OrderBy(t => Service.GetDisplayName(t)).ToArray();
         var count           = types.Count();
         var manyToManyDone  = new List <string>();
         for (var i = 0; i < count; i++)
         {
             var thisType      = types.ElementAt(i);
             var thisTypeLabel = Service.GetDisplayName(thisType);
             controller.UpdateProgress(i, count, "Exporting Relationships For " + thisTypeLabel);
             try
             {
                 var relationships = Service.GetManyToManyRelationships(thisType);
                 for (var j = 0; j < relationships.Count(); j++)
                 {
                     var relationship = relationships.ElementAt(j);
                     try
                     {
                         if (relationship.RecordType1 == thisType
                             ||
                             (!request.DuplicateManyToManyRelationshipSides &&
                              !manyToManyDone.Contains(relationship.SchemaName))
                             )
                         {
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.RecordType1, relationship.RecordType2,
                                                                        relationship.IsCustomRelationship, relationship.RecordType1DisplayRelated,
                                                                        relationship.RecordType2DisplayRelated
                                                                        , relationship.Entity1IntersectAttribute, relationship.Entity2IntersectAttribute,
                                                                        RelationshipExport.RelationshipType.ManyToMany,
                                                                        relationship.RecordType1UseCustomLabel, relationship.RecordType2UseCustomLabel,
                                                                        relationship.RecordType1CustomLabel, relationship.RecordType2CustomLabel
                                                                        , relationship.RecordType1DisplayOrder, relationship.RecordType2DisplayOrder, relationship.MetadataId
                                                                        , null));
                             manyToManyDone.Add(relationship.SchemaName);
                         }
                         if (relationship.RecordType2 == thisType &&
                             (request.DuplicateManyToManyRelationshipSides ||
                              (!manyToManyDone.Contains(relationship.SchemaName))))
                         {
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.RecordType2, relationship.RecordType1,
                                                                        relationship.IsCustomRelationship, relationship.RecordType2DisplayRelated,
                                                                        relationship.RecordType1DisplayRelated
                                                                        , relationship.Entity2IntersectAttribute, relationship.Entity1IntersectAttribute,
                                                                        RelationshipExport.RelationshipType.ManyToMany,
                                                                        relationship.RecordType2UseCustomLabel, relationship.RecordType1UseCustomLabel,
                                                                        relationship.RecordType2CustomLabel, relationship.RecordType1CustomLabel
                                                                        , relationship.RecordType2DisplayOrder, relationship.RecordType1DisplayOrder
                                                                        , relationship.MetadataId, null));
                             manyToManyDone.Add(relationship.SchemaName);
                         }
                     }
                     catch (Exception ex)
                     {
                         response.AddResponseItem(
                             new CustomisationExporterResponseItem("Error Exporting Relationship",
                                                                   relationship.SchemaName, ex));
                     }
                 }
                 if (request.IncludeOneToManyRelationships)
                 {
                     var oneTorelationships = Service.GetOneToManyRelationships(thisType);
                     for (var j = 0; j < oneTorelationships.Count(); j++)
                     {
                         var relationship = oneTorelationships.ElementAt(j);
                         try
                         {
                             var isCustomRelationship = Service.FieldExists(relationship.ReferencingAttribute, relationship.ReferencingEntity) &&
                                                        Service.GetFieldMetadata(relationship.ReferencingAttribute, relationship.ReferencingEntity).IsCustomField;
                             allRelationship.Add(new RelationshipExport(relationship.SchemaName,
                                                                        relationship.ReferencedEntity, relationship.ReferencingEntity,
                                                                        isCustomRelationship, false,
                                                                        relationship.DisplayRelated
                                                                        , null, relationship.ReferencingAttribute,
                                                                        RelationshipExport.RelationshipType.OneToMany, false, relationship.IsCustomLabel,
                                                                        null, relationship.GetRelationshipLabel
                                                                        , 0, relationship.DisplayOrder, relationship.MetadataId, relationship.DeleteCascadeConfiguration));
                         }
                         catch (Exception ex)
                         {
                             response.AddResponseItem(
                                 new CustomisationExporterResponseItem("Error Exporting Relationship",
                                                                       relationship.SchemaName, ex));
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 response.AddResponseItem(new CustomisationExporterResponseItem("Error Exporting Relationships",
                                                                                thisType, ex));
             }
         }
         response.AddListToOutput("Relationships", allRelationship);
     }
 }