Beispiel #1
0
        private void PopulateRollupFields(Entity contact, int multiplier = 1)
        {
            var i = 0;

            foreach (var rollup in $ext_jmobjprefix$RollupService.GetRollupsForRolledupType(contact.LogicalName))
            {
                i++;
                if (rollup.ObjectType == typeof(int) &&
                    rollup.RollupType == RollupType.Count &&
                    XrmService.GetFieldMetadata(rollup.FieldRolledup, rollup.RecordTypeRolledup).AttributeType == AttributeTypeCode.Lookup)
                {
                    //this is for count of a lookup
                    //for this script it will already be populated
                }
                else if (rollup.ObjectType == typeof(int))
                {
                    contact.SetField(rollup.FieldRolledup, i * multiplier);
                }
                else if (rollup.ObjectType == typeof(Money))
                {
                    contact.SetField(rollup.FieldRolledup, new Money(i * multiplier));
                }
                else if (rollup.ObjectType == typeof(decimal))
                {
                    contact.SetField(rollup.FieldRolledup, new decimal(i * multiplier));
                }
                else if (rollup.ObjectType == typeof(DateTime))
                {
                    contact.SetField(rollup.FieldRolledup, new DateTime(DateTime.Now.Year, i, i * multiplier));
                }
                else if (rollup.ObjectType == typeof(string))
                {
                    contact.SetField(rollup.FieldRolledup, (i * multiplier).ToString());
                }
                else if (rollup.ObjectType == typeof(bool) &&
                         rollup.RollupType == RollupType.Exists &&
                         XrmService.GetFieldMetadata(rollup.FieldRolledup, rollup.RecordTypeRolledup).AttributeType == AttributeTypeCode.Lookup)
                {
                    //this is for exists
                    //for this script it will already be populated
                }
                else
                {
                    throw new NotImplementedException("Not implemented for type");
                }
            }
        }