Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

Posted on by 275

Hello

I'm working on a plugin which needs to update opportunity field, but before updating the opportunity record I'm checking if the opportunity is open, if not I need to reopen it ( like we reopen it manually using ribbon button) without mentioning the status reason as there is another process which changes manually reopened opportunity's status reason.

if (IsOpportunityClosed(opportunityRef.Id, localcontext))

{
 /* Reopen the Opportunity record */
 SetStateRequest openOpp = new SetStateRequest();
 openOpp.EntityMoniker = opportunityRef;
 openOpp.State = new OptionSetValue(0);
 openOpp.Status = new OptionSetValue(100000044);
localcontext.OrganizationService.Execute(openOpp);
                                       
}


In, above code I'm using 100,000,044 as status. I'm wondering is there a way to reopen Opportunities without setting value of Status? Thanks in advance.

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

    That button is using javascript, so it might simply be passing default status id to the same request.

    Either way, Status is a required field, according to this:

    msdn.microsoft.com/.../microsoft.crm.sdk.messages.setstaterequest.aspx

    What I am wondering about, though, is why is this causing a problem at all?

  • Turbo Forms Profile Picture
    Turbo Forms 275 on at
    RE: Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

    What I mean to say is , the Reopen Opportunity ribbon Button can open a closed opportunity without worrying about status.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

    You are trying to ask the same question differently:)) I don't think there is any other way. Whether it's closed or active is all about the "state" field. Each state has a unique set of statuses. If you change state, you have to specify which status it's going to be.

  • Turbo Forms Profile Picture
    Turbo Forms 275 on at
    RE: Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

    Hi Alex thanks for replying. Is there any other way to reopen an opportunity ?

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Reopen lost/won opportunity using C# without mentioning specific Opportunity StatusReason

    Hi,

     It has to know the status - those two fields are connected.. there are different statuses per state..if you only update the state, it won't match the status anymore, so the whole request will fail

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

Featured topics

Product updates

Dynamics 365 release plans