Hi everyone,
I have 2 main account forms: FormA & FormB
and I have a field called "accountType" (option set) in both forms with values: A1, A2, A3, A4, A5
I would like to see the values A1, A2, and A3 in FormA in accountType optionset and I would like to see the values A4 and A5 in FormB in accountType optionset.
I'm guessing I would have to use some JavaScripting. Does anyone have the code for this requirement?
Thank you!
*This post is locked for comments
I've got it to work now,
It was an issue with the else if as well as the quotation marks. Here is my code:
function agentTypeOptionSetLoad() {
var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
if (formName == "Account - Organization") {
Xrm.Page.getControl('new_accounttype').removeOption(3);
Xrm.Page.getControl('new_accounttype').removeOption(4);
Xrm.Page.getControl('new_accounttype').removeOption(5);
Xrm.Page.getControl('new_accounttype').removeOption(6);
Xrm.Page.getControl('new_accounttype').removeOption(7);
}
else if (formName == "Account - Site") {
Xrm.Page.getControl('new_accounttype').removeOption(1);
Xrm.Page.getControl('new_accounttype').removeOption(2);
Xrm.Page.getControl('new_accounttype').removeOption(6);
Xrm.Page.getControl('new_accounttype').removeOption(7);
}
else if (formName == "Account - Distributor") {
Xrm.Page.getControl('new_accounttype').removeOption(1);
Xrm.Page.getControl('new_accounttype').removeOption(2);
Xrm.Page.getControl('new_accounttype').removeOption(3);
Xrm.Page.getControl('new_accounttype').removeOption(4);
}
}
Thanks for your help guys!
Hi,
I have tried else if too and it still gives me a scripting error.
I also tried adding the header prefix since the field is in the header but it still gives me an error.
Thanks
Hi,
it your last condition either you write else{....}
or you write else if(formName == 'Account - Distributor'){...}
Ive been scratching my head over this for a while now but its giving me a script error. This is my code:
function agentTypeOptionSetLoad() {
var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
if (formName == 'Account - Organization') {
Xrm.Page.getControl('new_accounttype').removeOption(3);
Xrm.Page.getControl('new_accounttype').removeOption(4);
Xrm.Page.getControl('new_accounttype').removeOption(5);
Xrm.Page.getControl('new_accounttype').removeOption(6);
Xrm.Page.getControl('new_accounttype').removeOption(7);
}
else if (formName == 'Account - Site') {
Xrm.Page.getControl('new_accounttype').removeOption(1);
Xrm.Page.getControl('new_accounttype').removeOption(2);
Xrm.Page.getControl('new_accounttype').removeOption(6);
Xrm.Page.getControl('new_accounttype').removeOption(7);
}
else (formName == 'Account - Distributor') {
Xrm.Page.getControl('new_accounttype').removeOption(1);
Xrm.Page.getControl('new_accounttype').removeOption(2);
Xrm.Page.getControl('new_accounttype').removeOption(3);
Xrm.Page.getControl('new_accounttype').removeOption(4);
}
}
Im getting a scripting error. Please help.
Thanks!
Hi,
here are some useful link to help you out:
community.dynamics.com/.../195852
On onload of form you have to write a javascript to remove options based on form. You can use below code snippet.
function agentTypeOptionSetLoad() {
var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
if (formName == 'formA') {
Xrm.Page.getControl('accountType').removeOption(4);
Xrm.Page.getControl('accountType').removeOption(5);
}
else if (formName == "formB") {
Xrm.Page.getControl('accountType').removeOption(1);
Xrm.Page.getControl('accountType').removeOption(2);
Xrm.Page.getControl('accountType').removeOption(3);
}
}
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6