web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Need to change publisher on CRM Solution using C# code

(0) ShareShare
ReportReport
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
    505 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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

Featured topics

Product updates

Dynamics 365 release plans