Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

(0) ShareShare
ReportReport
Posted on by 25

While creating new lead from SDK in CRM 2016, I am passing statecode=1(Qualified) and statuscode=3(Qualified) but getting below exception. Could not figure out the root cause of it.

 

Requesting experts to help.

Lead-Error.PNG

*This post is locked for comments

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

    Hi,

    Are you trying to create a lead with status as Qualified? If yes it won't work because by default crm create the record in open state. You could create the lead and then call set state post creation-

    Sample code-

    ---------

    using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))

               {

                   var newLead = new Entity("lead");

                   newLead["subject"] = "new lead 1";

                   newLead["firstname"] = "Test";

                   newLead["lastname"] = "Last1";                

                   var leadiId = service.Create(newLead);

                   SetStateRequest setStateRequest = new SetStateRequest();

                   setStateRequest.EntityMoniker = new EntityReference("lead", leadiId);

                   setStateRequest.State = new OptionSetValue(1);

                   setStateRequest.Status = new OptionSetValue(3);

                   service.Execute(setStateRequest);

               }

    ---------

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

    Please share you code.

    Refer the standard code in below links. Advise you to check to which version of crm this code applies.

    https://msdn.microsoft.com/en-us/library/hh547458.aspx

    https://www.inogic.com/blog/2016/11/qualify-lead-using-web-api-in-dynamics-365/

  • Nishant Arora Profile Picture
    25 on at
    RE: Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

    I checked the statecode and statuscode  are same what we got in vanilla version.

    Also If you see I am passing statecode=1(Qualified) and statuscode=3(Qualified) which is what we have by default for lead.

    I want to understand is there any thing which I am missing as I am trying to create lead status as Qualified.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

    Hi,

    Based on the error message, the code is not setting the statecode 1, it is still setting the statecode as o (Open). Debug your code and see if the field statecode is correctly setting.

    You can also share your code here for review.

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Create Lead Exception: 3 is not a valid status code for state code LeadState.Open on lead with Id

    Please check the available Statecodes and Status codes on lead in your environment. I think statecode and statuscode values are different in your environment.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans