Example #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);
        }
Example #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);
                }
            }
        }
Example #4
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);
     }
 }