Dear all
I do have two form types of OPPORTUNITY, as below , these are two different forms with different fields, now , ONE agent can create opportunities of different types (different forms), my issue is that when opening an existing opportunity, system does not open the right form for that opportunity, instead, it opens that last opened form.
So , how to configure system to open the right form type that belongs to a particular opportunity record.
Thanks,
Hi Ahmad,
You can do this using form selector.
here are some information
community.dynamics.com/.../226961
community.dynamics.com/.../180615
Ideally out of the box its not possible because dynamics CRM records does not associate with the form id so CRM does not know which form you basically create the record .
So it will be better that keep a flag (Or any existing field by which you identify the record to open which form) to identify when and which forms the record is created and based on the flag value redirect the particular form in the update mode. Here is the sample code to do that , Make sure you register below method in both the form on load , just change the form names and the flag field name .
Hope this helps
function OnLoadFormSelector() { if (Xrm.Page.ui.getFormType() == 2) { // This will trigger only when Update form var lblForm; var marketType = Xrm.Page.getAttribute("new_markettype").getValue(); //Get the optionset value , replace the optionset field name switch (marketType) { case 100001: // Replace the optionset value lblForm = "Opportunity Form 1"; // Replace Form name based on optionset value break; case 100003: lblForm = "Opportunity Form 2"; break; default: lblForm = "Opportunity Form 1"; } var formLabel = Xrm.Page.ui.formSelector.getCurrentItem().getLabel(); if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) { var items = Xrm.Page.ui.formSelector.items.get(); for (var i in items) { var item = items[i]; var itemId = item.getId(); var itemLabel = item.getLabel() if (itemLabel == lblForm) { if (itemLabel != formLabel) { item.navigate(); } } } } } }
thanks, but i am facing an error when opening an existing opportunity.
the code is :
function OnLoadFormSelector() {
if (Xrm.Page.ui.getFormType() == 2) { // This will trigger only when Update form
var lblForm;
//THIS LINE IS GENERATING THE ERROR
var OPP_Type = Xrm.Page.getAttribute("hsc_originatingleadtype").getValue(); //Get the optionset value , replace the optionset field name
switch (OPP_Type) {
case "Restaurant Lead": // Replace the optionset value
lblForm = "Opportunity-form-1"; // Replace Form name based on optionset value
break;
case "Marketing Lead":
lblForm = "Opportunity-form-2";
default:
lblForm = "Opportunity";
}
var formLabel = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var item = items[i];
var itemId = item.getId();
var itemLabel = item.getLabel()
if (itemLabel == lblForm) {
if (itemLabel != formLabel) {
item.navigate();
and the error Is :
TypeError: Cannot read property 'getValue' of null
at OnLoadFormSelector (hungerstation-sb.crm4.dynamics.com/.../hsc_opportunity_form_selector_based_on_lead_type)
thanks.
Hello Ahamad,
Xrm.Page.getAttribute("hsc_originatingleadtype").getValue(); it will retrieve the option set value (number), you can use Xrm.Page.getAttribute("hsc_originatingleadtype").getText(); for retrieving the option set label (text).
Also try to debug your code by using the the browser : developers.google.com/.../javascript
Hope this help.
thanks you Abed
but the i got the same error.
note: the field type is text-calculated field. i tried both getText and getValue and both gave me the same error.
thanks,
Make sure hsc_originatingleadtype field available in the form.
it worked finally.
appreciate your help usual Goutam.
regards.
Business Applications communities