Reputation: 219
In my entity i used two option sets... option set one(name---> new_location) contains items like Hyderabad,Mumbai
option set two(name---> new_places) contains items like Hussainsagar,Tank Bund,Imax , Bandra-Worli Sea Link,Marine Drive,Mount Mary Church.
If I select Hyderabad in option set one option set two displays first 3 items i.e Hussainsagar,Tank Bund,Imax if I select Mumbai option set two shows remaining items...
Hoe it is possible..??
Please help me!
Upvotes: 2
Views: 4060
Reputation: 1467
This is OK for very short sets, but quickly becomes unmanageable and the scripts get very big. Consider instead using two custom entities - one for city, one for region / area / place (whatever you want to call it)
Add a relationship to each of these from Account (so Account N:1 city / place) and add these new lookup fields on the Account form
On the region entity add a lookup to the city it is in and make this a required field.
Now you can easily filter the place according to the city with no scripts required - edit the place field on the Account form and on the "Display" tab look for "Related records filtering". Filter places so they only show places that are in the city already selected on the account.
You can easily import cities and their places using the normal data import methods (rather than building option sets by hand). You can also control which users can add new cities or places (ie use the "New" button in the lookup) without then having any admin access rights, so a manager can add new cities, and maybe other staff can only add places in existing cities.
And you can use these same entities for lookups on Accounts, Contacts, leads - wherever you want really!
Don't forget users will all need some rights to the new entities, specifically the "read" and "append to" privileges.
Upvotes: 1
Reputation: 619
Here is sample code to do it:
optionSetChanged = function () {
var optionsetControl = Xrm.Page.ui.controls.get("new_places");
var options = optionsetControl.getAttribute().getOptions();
var value = Xrm.Page.getAttribute("new_location").getValue();
// first option is selected
if (value == 1) {
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++) {
if (i == 0 || i == 1) {
optionsetControl.addOption(options[i]);
}
}
}
// else is second option is selected
else if (value == 2) {
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++) {
if (i == 2 || i == 3 || i == 4) {
optionsetControl.addOption(options[i]);
}
}
}
}
Hope it's clear!
Upvotes: 2