Link to home
Start Free TrialLog in
Avatar of apollo7
apollo7Flag for United States of America

asked on

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

Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

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.
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.
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.
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

What errors you are getting? Are you able to run the  program? Or you are getting errors at compile time?
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.
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.
From where did you get this code?
Also you can get compatible version of XRM Toolbox along with the plug-ins. Just check the downloads section.
Don't worry I thought we had to update other records. I will post complete code.
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here :)
                organization["currentcasenumber"] = 1005;

Open in new window

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