As many of us know, for unified interface now we can customize the “opportunityclose” entity. A feature awaited for a very long time and finally it’s here.
If you are not aware, you can now customize the dialog box that pops up when you click “Close as Won” and “Close as Lost” button on the opportunity. The entity is “opportunityclose” entity. For more details, please refer the below links
– https://docs.microsoft.com/en-us/dynamics365/sales-enterprise/enable-opportunity-close-customization
– https://docs.microsoft.com/en-us/dynamics365/sales-enterprise/customize-opportunity-close-experience
So you can customize the opportunityclose form and add your custom fields as well. But the same form fires both when you click “Close as won” or “Close as lost” button. My customer had a requirement where based on the button clicked, appropriate fields need to show up and certain business logic need to be performed when the “Opportunity Close” form is loading.
Just when I was about to pose before my customer as “know it all person”, Dynamics 365 again intervened and put me in proper place. So I was back to drawing boards. The first thing that struck me was – “How is this quick create form getting launched?”. In the ribbon workbench I evaluated “Close as won” button and found the below action.
Now we are going to modify the Opportunity system library script file. Ahhhhhhhhh..Just joking.
The important thing to note here is the “Boolean parameter” which is passed to the function. So the key takeaway from here is the system function is taking this boolean parameter as input and then passing this parameter to the Quick create form of opportunity close.
Now things are sorted out. A quick guess – this parameter must be passed as a Querystring parameter to the Quick create form. And hell yeah! I was right.
function formLoad (e) {
debugger;
var isCloseAsLostClicked = false;
var fc = e.getFormContext();
var gc = Xrm.Utility.getGlobalContext();
var queryString = gc.getQueryStringParameters();
isCloseAsLostClicked = queryString[“param_won”]; // value will be true for won and false for lost button click.
}
I have highlighted the lines of code here which will help you determine whether “Close as Won” or “Close as Lost” was clicked.
Once you have that information, it’s up to you to utilize this information. Cool isn’t it?
Before I end, this will work for Unified interface only as the feature of customizing opportunityclose entity is supported only for Unified interface.
P.S – Haven’t found this documented in MS docs. So obviously can’t vouch whether this parameter will always be there. As of now validated for multiple environments and scenarios and it worked just fine. Would be happy for alternatives.
Hope this helps!
Debajit Dutta
(Dynamics MVP)
For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
Our product offerings:
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)
Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.