Hi,
I have requirement to close opportunity using asp.net application. Please share if any example.
Thanks,
Sandeep
*This post is locked for comments
Hi,
I have requirement to close opportunity using asp.net application. Please share if any example.
Thanks,
Sandeep
*This post is locked for comments
LOSE. LoseOpportunityRequest
Hi
Did you use correct CRM version SDK? Please refer below URL
msdn.microsoft.com/.../microsoft.crm.sdk.messages.winopportunityrequest.aspx
Never mind, I found it in Microsoft.Crm.Sdk.Messages;
What namespace is needed for WinOpportunityRequest and LostOpportunityRequest? These don't resolve in my code. I've got these using statements:
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.WebServiceClient;
Hi Sandeep,
You can use following code to Close Opportunity as Won or Lost.
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.Depth > 1) return;
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// For Close Opportunity as Won
var winOppRequest = new WinOpportunityRequest
{
OpportunityClose = new OpportunityClose
{
OpportunityId = new EntityReference
(Opportunity.EntityLogicalName, entity.Id)
},
Status = new OptionSetValue(3)
};
service.Execute(winOppRequest);
// For Close Opportunity as Lost
var LostOppRequest = new LoseOpportunityRequest
{
OpportunityClose = new OpportunityClose
{
OpportunityId = new EntityReference(Opportunity.EntityLogicalName, entity.Id)
},
Status = new OptionSetValue(4)
};
service.Execute(LostOppRequest);
}
}
Hope it will helps you,
Thanks.
Hi,
You can refer below link to connect with CRM which will help you to retrieve proxy.
https://msdn.microsoft.com/en-us/library/gg309393.aspx
After that you can get the service object using proxy. Then you can refer below link to close opportunity.
https://nishantrana.me/2008/07/11/closing-an-opportunity-programmatically-crm/
Hope this helps for you.
Thanks!
Sam
HI ,
Please follow the below links if they might help :
nishantrana.me/.../closing-an-opportunity-programmatically-crm
social.microsoft.com/.../crm-2011-plugin-for-opportunity-close
Thanks !
Here the Code to Close the Oppty. Hope it will help you.
private void WinOpportunity(IOrganizationService organizationService, Opportunity opportunity)
{
OpportunityClose oppClose = new OpportunityClose
{
OpportunityId = opportunity.ToEntityReference(),
Subject = "Won!",
ActualEnd = DateTime.Now,
Description = "Won!",
};
var req = new WinOpportunityRequest
{
OpportunityClose = oppClose,
RequestName = "WinOpportunity",
Status = new OptionSetValue(3)
};
var response = (WinOpportunityResponse)organizationService.Execute(req);
var results = response.Results;
}
Thanks,
Rajeev
1. Initialize the organizationserviceproxy in your application.
2. Use WinOpportunityRequest or LostOpportunityRequest and execute this organization request in your application.
Please let me know if you need more help.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156