Hello,
I want to close an opportunity (automatically) when today’s date is greater than the last date. I think I need to write a rule that triggers this, but what formula to identify today’s date though ?
Hello,
I want to close an opportunity (automatically) when today’s date is greater than the last date. I think I need to write a rule that triggers this, but what formula to identify today’s date though ?
Hi partner,
For example you want to close an existing record as win, this code will close the opportunity.
service.Execute(winOpp);
And under the foreach function, you could add custom filters as your rquirements.
foreach(var c in result.Entities)
{//add filters... }
The "result.Entites" contains all the opportunity records and in this foreach function, you could do actions on each record.
Like: if (c.Attributes["field"]="Past Last Date")
{//to do... }
Hope it helps.
Best Regards,
Leo
Great, thanks for the example.
If we create a new record just to close it, how does that close the existing records that needs to be close and can we close it base on a status of our choosing in this case as “Past Last Date”.
Hi partner,
Consider that we could not let the coding programs keep running 24-hour in the background(beacuse D365 only allows each process to run up to 7 times per hour), I suggest that you could write a c# app to Screen out all opportunities that meet the conditions and close them at a special time everyday e.g Every day at 2 a.m. You could add this app to Windows task scheduler and let it run everyday 2.00 am automatically.
Here is the sample code for you.
Note that, in C# we could not close the opportunities by setting "statuscode", we need to create a new record of "winopportunity" or "loseopportunity" which Corresponding to "Win" and "Lose".
And remember to add "Microsoft.CrmSdk.Xrm.Tooling.CoreAssembly" to NuGet.
Hope it helps.
Best Regards,
Leo
Hi Partner,
Thanks for your answer and advice.
What we want to do is when today’s date is greater than last date. The opportunity is closed past last date. We want this to do automatically to all opportunity that fits this description.
I think as you indicated is best to create a C# program in console as executable and schedule it to run which I think is great. Could you please provide some examples ?
Hi partner,
May I know what's the trigger conditions do you want. 24-hour real-time monitoring or some other special circumstances trigger this operation?
If you want this rule to monitor dates in real time in the background, turn off the opportunity as soon as conditions are met, you need to create a console-app with C# to Compare 2 dates and close the opportunity and then create a windows task scheduler to let the console app runs every day.
If you want to trigger this feature in other situations, such as when adding, upgrading, or deleting opportunities, you could create a workflow to do this.
If my understanding is not correct, please kindly share yor complete requirement.
Hope it helps.
Bset Regards,
Leo
Hi Johnseito,
It depends on what programming language you are using to solve the problem. For example, in C# you can use the DateTime.Now Property to get a DateTime object that is set to the current date and time on your computer, expressed as the local time.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156