Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Need to change publisher on CRM Solution using C# code

Posted on by 325

Hi All,

Does anyone know how we can modify settings of a CRM solution using C# code? Like we need to change publisher using C# coding in a console application or some other application.

We need to remove the existing publisher and set another publisher programmatically using C# code.


Thanks

  • Verified answer
    Thangamani Profile Picture
    Thangamani 507 on at
    RE: Need to change publisher on CRM Solution using C# code

    Hi Muhammad,

        As per CRM SDK we will be able to create,update and retrieve the publishers of the solution.Below is the code for to create the publisher via programmatically.Use the code to create a new publisher and update the same publisher for a solution just using the update request instead of create.WHile updating you need to provide the ID of the publisher which is created.

    /Define a new publisher

                       Publisher _crmSdkPublisher = new Publisher

                       {

                           UniqueName = "sdksamples",

                           FriendlyName = "Microsoft CRM SDK Samples",

                           SupportingWebsiteUrl = "msdn.microsoft.com/.../default.aspx",

                           CustomizationPrefix = "sample",

                           EMailAddress = "someone@microsoft.com",

                           Description = "This publisher was created with samples from the Microsoft Dynamics CRM SDK"

                       };

                       //Does publisher already exist?

                       QueryExpression querySDKSamplePublisher = new QueryExpression

                       {

                           EntityName = Publisher.EntityLogicalName,

                           ColumnSet = new ColumnSet("publisherid", "customizationprefix"),

                           Criteria = new FilterExpression()

                       };

                       querySDKSamplePublisher.Criteria.AddCondition("uniquename", ConditionOperator.Equal, _crmSdkPublisher.UniqueName);

                       EntityCollection querySDKSamplePublisherResults = _serviceProxy.RetrieveMultiple(querySDKSamplePublisher);

                       Publisher SDKSamplePublisherResults = null;

                       //If it already exists, use it

                       if (querySDKSamplePublisherResults.Entities.Count > 0)

                       {

                           SDKSamplePublisherResults = (Publisher)querySDKSamplePublisherResults.Entities[0];

                           _crmSdkPublisherId = (Guid)SDKSamplePublisherResults.PublisherId;

                           _customizationPrefix = SDKSamplePublisherResults.CustomizationPrefix;

                       }

                       //If it doesn't exist, create it

                       if (SDKSamplePublisherResults == null)

                       {

                           _crmSdkPublisherId = _serviceProxy.Create(_crmSdkPublisher);

                           Console.WriteLine(String.Format("Created publisher: {0}.", _crmSdkPublisher.FriendlyName));

                           _customizationPrefix = _crmSdkPublisher.CustomizationPrefix;

                       }

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans