I have two lead forms created. One for Office Furniture Product Line and the other for Home Furniture Product line. Now, I've a field set as option type with values Office Furniture and Home Furniture. When the user chooses Home Furniture Lead Form, the form must be able to set Home Furniture as a static value and read-only. Similarly, If it is Office Furniture lead form, the Office Furniture must be set up as a static value read-only. In a way, We want to take away the editing capability for this field from the user. I'm facing a challenge here because the same field is referenced in both the forms. If I set Home Furniture as default value and make it read-only, the office furniture lead form also displays the same value. If anyone could help me with a script to assign 2 different values based on Lead form selection, it'd be a great help.
2 Answers
1
votes
I was able to show the results through this.But I wrote two different functions one for each form
function HomeFurniture() {
Xrm.Page.getAttribute("new_lineofbusiness").setValue(100000000);
}
On the other form I inserted the same function
function OfficeFurniture() {
Xrm.Page.getAttribute("new_lineofbusiness").setValue(100000000);
}
0
votes
you need to check in which form you are and set the field, you can start from this example:
var currentForm = Xrm.Page.ui.formSelector.getCurrentItem();
if (currentForm != null) {
var formValue = null;
var currentFormLabel = currentForm.getLabel();
switch (currentFormLabel) {
case "Office Furniture":
formValue = 1;
break;
case "Home Furniture":
formValue = 2;
break;
}
if (formValue != null) {
Xrm.Page.getAttribute("new_formtype").setValue(formValue);
Xrm.Page.getAttribute("new_formtype").setSubmitMode("always");
Xrm.Page.getControl("new_formtype").setDisabled(true);
}
}
of course only this code will not be enough, you need to take care when the user change the form (if you want to leave this possibility) or change automatically the form using the navigate method.
I suggest this msdn article, will be helpful: