Hi everyone,
I have 3 main forms in the account entity
- formA, formB, and formC
When I open some previously created record, it open in the form which was last opened by the user.
I want to open the form in which the record was originally created in.
Does anyone have code for the same requirement?
Thanks
*This post is locked for comments
Figured it out.. Here is the correct function. There was a parenthesis problem that was causing the issue. Thanks to everyone who helped me!
function onLoad()
{
//if the form is update form
if (Xrm.Page.ui.getFormType()==2){
// variable to store the name of the form
var lblForm;
// get the value picklist field
var relType = Xrm.Page.getAttribute("new_formname").getValue();
// switch statement to assign the form to the picklist value
//change the switch statement based on the forms numbers and picklist values
switch (relType) {
case 'AccountC':
lblForm = "AccountC";
break;
case 'AccountB':
lblForm = "AccountB";
break;
default:
lblForm = "AccountA";
}
//check if the current form is form need to be displayed based on the value
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) {
//navigate to the form
item.navigate();
return;
} //endif
} //end for
} //endif
}
}//endif
I am still experiencing a few issues.
1) When I create a new record and click on "save and close" or "save" it saves and automatically opens a new AccountA form. When I try to switch to AccountB or Account C form from the dropdown, it gives this the following pop up and again opens AccountA form.
Any changes to be made to the code?
It works like a charm! Thank you so much!!
Hello,
There is issue in your code, use following code, it's working fine for me
function onLoad() { //if the form is update form if (Xrm.Page.ui.getFormType()==2) // variable to store the name of the form var lblForm; // get the value picklist field var relType = Xrm.Page.getAttribute("new_formname").getValue(); // switch statement to assign the form to the picklist value //change the switch statement based on the forms numbers and picklist values switch (relType) { case 'AccountC': lblForm = "AccountC"; break; case 'AccountB': lblForm = "AccountB"; break; default: lblForm = "AccountA"; } //check if the current form is form need to be displayed based on the value 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) { //navigate to the form item.navigate(); return; } //endif } //end for } //endif }//endif
@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx line 159 > eval:1:1
RunHandlerInternal@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
RunHandlers@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
OnScriptTagLoaded@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
AppendScriptTag/scriptTag.onload/<@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
This is the log file. Thank you.
Hello,
Can you download and share log file here, in what line you are getting this error ??
Hello,
I used the alert(relType) and it returned the form name from custom field on the pop up. I am getting the following page script error.
I am unable to debug the error. Please offer a solution.
Thanks.
Hello,
First make sure this field have value or not, you can simply put a alert on that, alert(relType ), you can also debug your script just using debugger keyword, are you getting any error ?? any page script error ??
Thanks
I have applied the following code for my custom field "new_formname" but it isnt working. It is a single line of text field and not a picklist field (does that make a difference - any changes in code necessary?).
Please help. Thanks.
//if the form is update form
if (Xrm.Page.ui.getFormType()==2)
// variable to store the name of the form
var lblForm;
// get the value picklist field
var relType = Xrm.Page.getAttribute("new_formname").getValue();
// switch statement to assign the form to the picklist value
//change the switch statement based on the forms numbers and picklist values
switch (relType) {
case 1:
lblForm = "AccountC";
break;
case 2:
lblForm = "AccountB";
break;
default:
lblForm = "AccountA";
}
//check if the current form is form need to be displayed based on the value
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) {
//navigate to the form
item.navigate();
} //endif
} //end for
} //endif
}//endif
} //end function
I have applied function on my forms to save the form name on a custom field.
Now, how can I open the corresponding form? Can you please share the code for the same. Thanks in advance.
André Arnaud de Cal...
292,162
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156