Help developing a console app to change Autonumber in Settings

I am trying to use the code below to change the AutoNumber value in Settings.

(this code was obtained from:  https://community.dynamics.com/crm/b/hayersdynamicscrm/archive/2016/02/03/how-to-reset-auto-numbering-in-dynamics-crm-online)

According to the post, because the number is greyed-out, it can't be changed through UI.
But we can write a small console application to update it using SDK.

In my case, I want to update the  CurrentCaseNumber, but I need help developing a console application to do that.


 {"organizationid", "name", "currentkbnumber"})

    };

    EntityCollection orgs = service.RetrieveMultiple(qe);




    if (orgs != null && orgs.Entities.Count > 0)

    {

        var org = orgs[0];

        var organizationId = (Guid)org["organizationid"];




        // Creating a new Object to update. Set the  CurrentCaseNumber to your desired number

        OrganizationorganizationToUpdate = new Organization {  CurrentCaseNumber = 100000, Id = organizationId};

        service.Update(organizationToUpdate);

    }    
]

Open in new window

LVL 1
apollo7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

I am hoping this is the latest Dynamics 365 Online environment you are trying to work with. I suggest you follow the sample that is given here:
https://code.msdn.microsoft.com/Sample-Quick-start-for-650dbcaa

Once you are able to connect to your organization
1. Either Query CRM or use a CSV/Database for the updates
2. Call the Update method with appropriate GUID, entity type and CaseNumber.

Let me know if you run into any issues.

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

Before we get into further troubleshooting, the version of your CRM Server? Also have you updated the sample code Nuget packages? Generally, the samples are built using at that time latest packages and after that many updates are pushed so it is a good practice to get the latest assemblies from Nuget.

You should enter the server name as: crm.dynamics.com. Have you tried that?

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

I am sorry that it is not working out. Instead of trouble shooting that code I suggest let's do it my way. This is my tutorial that I use when I have to connect to CRM in quickest possible way. I do not recommend this method for production usage as it will store user name and password in plaintext. Ideally, you should encrypt the connection string section if you want to use this method.

1. Create a new, empty Console app. Please make sure you are targeting framework 4.7.1 or above.
2. Solution Explorer -> Right click on your project -> Manage Nuget Packages...
3. Click on Browse -> Search for : Microsoft.CrmSdk.XrmTooling.CoreAssembly
4. You will find the exact assembly with this name. Install it. It will install multiple other things, please accept any EULA dialogs that appear.
5. Solution Explore -> app.config -> Add the following code inside Configuration tag
<connectionStrings>
    <add name="TrippConsulting" connectionString="AuthType=Office365;Username=YOURUSERNAME; Password=YOURPASSWORD;Url=https://trippconsulting.crm.dynamics.com"/>
</connectionStrings>

Open in new window

6. Open Program.cs
7. Add the following in Using block
using Microsoft.Xrm.Tooling.Connector;
using System.Configuration;

Open in new window

8. In your Program.cs
    static void Main(string[] args)
        {
            Run();
        }

        private static void Run()
        {
            CrmServiceClient client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["TrippConsulting"].ConnectionString);
            if (client.IsReady)
            {
                Console.WriteLine(client.ConnectedOrgFriendlyName);
                Console.WriteLine(client.ConnectedOrgUniqueName);
                Console.WriteLine(client.ConnectedOrgVersion);
            }
            Console.ReadKey();
        }

Open in new window


Regards,
Chinmay.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Chinmay PatelChief Technical NinjaCommented:
5. Solution Explore -> app.config -> Add the following code inside Configuration tag

Because I clearly said :) Add the following code inside configuration tag. It should look something like this.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
    </startup>
<connectionStrings>
YOUR CONNECTION STRING GOES HERE :)
</connectionStrings>
</configuration>

Open in new window

0
Chinmay PatelChief Technical NinjaCommented:
What errors you are getting? Are you able to run the  program? Or you are getting errors at compile time?
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

using System;
using System.IO;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System.Configuration;

namespace CrmXpress.EEConsole
{
    class Program
    {

        static void Main(string[] args)
        {
            Run();
        }

        private static void Run()
        {
            CrmServiceClient client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["TrippConsulting"].ConnectionString);
            if (client.IsReady)
            {
                Console.WriteLine(client.ConnectedOrgFriendlyName);
                Console.WriteLine(client.ConnectedOrgUniqueName);
                Console.WriteLine(client.ConnectedOrgVersion);
            }
            Console.ReadKey();
        }

    }
}

Open in new window


I think we have to look at alternatives, this is going to get complex.

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

You have to include

using System.Configuration;

Open in new window


In the namespace import section. If you have it then, you might be missing a reference and you can add it from Project menu.

I can guide you through the entire code or I can write the entire thing if you give me exact details(But it has to be Live - My charge is 0.0 but whatever EE charges are there, you will have to pay that) and I can hunt for an existing tool which you can use. I think the last option is the most suitable.

1. Please install XrmToolBox from: https://www.xrmtoolbox.com/
2. Once you download the zip -> Right Click on it -> Properties -> Unblock.
3. Extract the Zip.
4. Run XrmToolBox.exe. Click on Open Plugins Store from Quick Action Menu on your right hand side.
5. You can get two plugins: 1. Bulk Data Updater 2. Attribute Value Updater
6. Install both the plugins.
7. Give them a try and let me know if any of them are fitting your requirements.

If you still want to write the entire code from your end, I am going to provide as much as step by step guidance as I can.

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
From where did you get this code?
0
Chinmay PatelChief Technical NinjaCommented:
Also you can get compatible version of XRM Toolbox along with the plug-ins. Just check the downloads section.
0
Chinmay PatelChief Technical NinjaCommented:
Don't worry I thought we had to update other records. I will post complete code.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

Here is the complete program.cs code:

namespace CrmXpress.EEConsole
{
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Tooling.Connector;
    using System;
    using System.Configuration;

    class Program
    {
        static void Main(string[] args)
        {
            Run();
        }

        private static void Run()
        {
            CrmServiceClient client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["TrippConsulting"].ConnectionString);
            if (client.IsReady)
            {
                Console.WriteLine("\t\t-------------Connected to-------------");
                Console.WriteLine(string.Concat("Friendly Name : ", client.ConnectedOrgFriendlyName));
                Console.WriteLine(string.Concat("Unique Name : ", client.ConnectedOrgUniqueName));
                Console.WriteLine(string.Concat("Dynamics 365 Version : ", client.ConnectedOrgVersion));
            }
            Console.WriteLine("Press Any Key To Continue...");
            Console.ReadKey();

            QueryExpression query = new QueryExpression("organization")
            {
                ColumnSet = new ColumnSet(new string[] { "name", "currentcasenumber" })
            };

            EntityCollection result = client.RetrieveMultiple(query);

            if (result != null && result.Entities.Count > 0)
            {
                Entity organization = result[0];


                Console.WriteLine(string.Concat("Dynamics 365 OrgID: ", organization["organizationid"]));
                Console.WriteLine(string.Concat("Dynamics 365 Name: ", organization["name"]));
                Console.WriteLine(string.Concat("Current Case Number : ", organization["currentcasenumber"]));

                Console.WriteLine("Press Any Key To Continue...");
                Console.ReadKey();
                Console.WriteLine("Starting update to Current Case Number...");

                organization["currentcasenumber"] = 1005;
                client.Update(organization);

                Console.WriteLine("Updated Current Case Number Successfully.");
                Console.WriteLine("Press Any Key To Continue...");
                Console.ReadKey();
            }

        }
    }
}

Open in new window


Regards,
Chinmay.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chinmay PatelChief Technical NinjaCommented:
Here :)
                organization["currentcasenumber"] = 1005;

Open in new window

0
Chinmay PatelChief Technical NinjaCommented:
You have caught me at a bad time otherwise I think I could quickly spin up an app for this.
0
Chinmay PatelChief Technical NinjaCommented:
Glad I could help.
0
Chinmay PatelChief Technical NinjaCommented:
It did work for one but it is not working for another?
0
Chinmay PatelChief Technical NinjaCommented:
The code is fine. Is this new organization in Sandbox mode?
0
Chinmay PatelChief Technical NinjaCommented:
Please immediately remove the comment containing sensitive details..
0
Chinmay PatelChief Technical NinjaCommented:
Thank you. 🙂. I suggest wait for some time for Sandbox to reflect this change. Keep me posted if it doesn't work.
0
Chinmay PatelChief Technical NinjaCommented:
Also do change that password. Let's not take any risk.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

Is it possible for you to get in touch with MS Support or try to convert this instance to PROD and see if it gives desired results? I can give it a shot as well if you cant convert your instance for testing purpose.

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

It worked for the organization where I changed it and I think it worked for you as well once. I think it could be the number itself.

Would you like to try something? maybe changed it to a smaller format number once and try it in Prod. If it still does not work I think the fasted way to close this would be to contact Microsoft Support as the code successfully executes and the changes are posted(sometimes they are applied and sometimes they are not).

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

I was thinking about that tool when we began this discussion but when you said you just need to update it in the settings I thought that tool might not work for us. Also if it is already there I think we should not reinvent the wheel.

Let me know your thoughts.

Regards,
Chinmay.
0
Chinmay PatelChief Technical NinjaCommented:
Hi apollo7,

I don't think it will ever work for version below 9.0 before 9.0 this was not supported at all.

Regards,
Chinmay.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.