16 Aralık 2015 Çarşamba

CRM Versiyon Alma ( Retrieve the current CRM version)


 public enum CRMVersion
    {
        Unknown,
        CRM2011,
        CRM2011UR12PLUS,
        CRM2013,
        CRM2013SP1,
        CRM2015
    }

 public CRMVersion GetCRMVersion(IOrganizationService service)
        {
            RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
            RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)service.Execute(versionRequest);

            string version = versionResponse.Version;
            if (version.StartsWith("5"))
            {
                try
                {
                    int buildNumber = Convert.ToInt32(version.Substring(version.LastIndexOf(".") + 1));
                    if (buildNumber > 3000) { return CRMVersion.CRM2011UR12PLUS; }
                }
                catch { }
                return CRMVersion.CRM2011;
            }
            if (version.StartsWith("6.0")) { return CRMVersion.CRM2013; }
            if (version.StartsWith("6.1")) { return CRMVersion.CRM2013SP1; }
            if (version.StartsWith("7")) { return CRMVersion.CRM2015; }
            return CRMVersion.Unknown;
        }

10 Aralık 2015 Perşembe

CRM 2011 - Gelişmiş Bul 'da Her Sayfada Görünecek Kayıt Sayısını Değiştirme (Change the number of records per page in any list of records)

Aşağıdaki yazımda Gelişmiş Bul ;'da yapılan sorgulamada her sayfa için 50 adet kayıt listeleniyordu. Ben bunu her sayfada 250 kayıt gelecek şekilde değiştireceğim.

CRM ana ekranında File butonuna tıklayalım. Gelen seçeneklerden Options a tıklayalım.

Set Personal Options penceresinde General tabının altından Set the number of records per page in any list of records  kısmından her sayfada kaç adet kayıt geleceğini seçelim.Ok butonuna basalım.
 50 olan seçeneği 250 olarak değiştirelim..
 Seçeneğimi 250 olarak değiştirdikten sonra Ok butonuna basalım.
 Gelişmiş Bul 'u açalım ve ekranda 250 kayıt görelim.

CRM 2011 - Kullanıcı TimeZone Ayarları (CurrentUser Timezone Settings)

CRM ana ekranında File butonuna tıklayalım. Gelen seçeneklerden Options a tıklayalım.

Set Personal Options penceresinde General tabının altından Set the time zone you are in  kısmından Time Zone u seçelim.Ok butonuna basalım.




CRM 2011 QueryExpresison - Kullanıcı TimeZone Ayarları Çekme ( Retrive Current User TimeZone Settings)


public static  UserSettings GetCurrentUsersTimeZoneSettings(IOrganizationService crmService, Guid userid, ColumnSet columnset)
        {
            try
            {
                QueryExpression query = GetQueryExpressionSingle("usersettings", "systemuserid", userid, columnset);
                EntityCollection ec = crmService.RetrieveMultiple(query);
                if (ec != null && ec.Entities.Count == 1)
                    return (UserSettings)ec.Entities[0];
                else
                    return new UserSettings();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

GetQueryExpressionSingle metodu


Metot Kullanımı

UserSettings abc = CrmManagerStatic.GetCurrentUsersTimeZoneSettings(crmService, new Guid("D91E53ED-4AC1-E211-87D1-0050569505A4"), new ColumnSet("localeid", "timezonebias", "timezonecode"));
if (abc != null && abc.Id != Guid.Empty){

}
                                   

CRM 2011 Plugin - Merge Plugin Yazımı

Bu makalemde iki contact varlığının merge edildiğinde  çalışacak  pluginin nasıl yazılacağını anlatacağım.

Merge plugini yazımında context ten bize Target ve SubordinateId diye tanımlı InputParameterelere dikkat edeceğiz.Target parametresi bize geriye kalcak varlığın bilgisini verirken , SubordinateId parametresi bize deactivate olacak ikinci varlığın bilgisini verir.
Aşağıdaki kodları incelerseniz beni daha ii anlayacaksınız.

contact1 nesnesi işlem sonunda geriye kalan contact ı
contact2 ise deactivate olan contactı simgeler.

Kaynak Kodlar

public class ContactMerge : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            Guid contact1 = Guid.Empty;
            Guid contact2 = Guid.Empty;
            try
            {
                #region Plugin Tanımlamaları
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                serviceFactory.GetType().GetProperty("ProxyTypesAssembly").SetValue(serviceFactory, typeof(XrmServiceContext).Assembly, null);
                IOrganizationService crmService = serviceFactory.CreateOrganizationService(context.UserId);

                if (!context.InputParameters.Contains("Target"))
                    return;

                if (string.IsNullOrEmpty(context.MessageName))
                    return;

                if (!context.MessageName.Equals("Merge"))
                    throw new Exception("Plugin executed but message was not merge");
                #endregion
                #region Main Code
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
                {
                    EntityReference eTarget = (EntityReference)context.InputParameters["Target"];
                    contact1 = eTarget.Id;
                    contact2 = (Guid)context.InputParameters["SubordinateId"];

                    if (contact1 != Guid.Empty && contact2 != Guid.Empty)
                    {
                        Contact contact1Entity = (Contact)crmService.Retrieve("contact", contact1, new ColumnSet(new string[] { "contactid", "ite_industryid" }));
                        if (contact1Entity != null && contact1Entity.Id != Guid.Empty)
                        {
                        }
                        else
                            throw new Exception("Contact not found.");
                    }
                    else
                        throw new Exception("Contact1 or Contact2 id guid empty.");
                }
                else
                    throw new Exception("Not right type of target");
                #endregion
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the ContactMerge plug-in" + ex.Message);
            }
        }
    }

Plugin Registration Tool ile MErge Plugin Deploy Etme

Plugin inize aşağıdaki step i eklemeniz yeterli olacaktır.