Hi,
The feature I'm trying to achieve here is,
1) User select parent Industry
2) Based on user's selection it shows parent's child Industry
Currently, there is a web template which include following fetchxml for parent industry.
Hi Oliver, I solved it using oData my co-worker advised me like you mentioned.
>In you scenario, how does the user select the parent industry, and what happens after?
My Web Template has a fetchxml and javascript, when it loads it trigger fetchxml to get parent industry then it show parent dropdown list as follows.
<div class="col-sm-10">
<select id="parentindustryselect" class="form-control picklist" name="parentindustryname" onchange="showChildIndustry(value);">
{% if parentIndustryResults.size > 0 %}
{% for parentIndustry in parentIndustryResults %}
<option value="%{{parentIndustry.sab_industryid}}%">{{ parentIndustry.sab_name }}</option>
{% endfor %}
{% endif %}
</select>
</div>
When user select one of the parent industry, child industry select dropdown list needs to be populated.
What I did when form is ready get all child industry using oData then based on user selection, filtered it by parent industry and binding the result to child industry select dropdown element.
var allChildInustry = null;
$(document).ready(function () {
...
$.ajax({
type: "get",
url: "/_odata/industries_child_odata",
success: function (data) {
allChildInustry = data.value;
},
error: function () {
alert('Failed to retrieve all child industry');
}
});
});
...
function showChildIndustry(value) {
var name = $("#parentindustryselect option:selected").text();
// I can't use jQuery's grep and even filter function don't know why.
// var filterValue = $.grep(allChildInustry, function (child) {
// return child.sab_parentindustry.Id === value && child.sab_parentindustry.Name === name;
// });
// var filterValue = allChildInustry.filter(function (child) {
// return child.sab_parentindustry.Id === value && child.sab_parentindustry.Name === name;
// });
var filterValue = [];
for (var i = 0; i < allChildInustry.length; i++) {
var child = allChildInustry[i];
if (child.sab_parentindustry.Name === name) {
filterValue.push(child);
}
}
$('#childindustryselect').empty();
for (var i = 0; i < filterValue.length; i++) {
console.log(filterValue[i].sab_name + " ::::: " + filterValue[i].sab_industryid);
$('#childindustryselect').append('<option value=' + filterValue[i].sab_industryid + '>' + filterValue[i].sab_name + '</option>');
}
}
However, after selecting child industry and other criteria, it needs to show final result. It could be another fetchxml call or etc.
Anyway thanks a lot Oliver.
Hi, you are right in regards the XRM object, we can't use it in the Portals
In you scenario, how does the user select the parent industry, and what happens after?
if you are redirected to a different page, you can just run your fetch filtered by the parent
another (ugly) option would be having a join in your fetch retrieving both parent and child, and use Liquid filters, grouping the items in your initial list list, and then re-referencing the same list to display the children - docs.microsoft.com/.../liquid-filters
another option if you are using JavaScript is instead of having liquid/fetch for the children you can consider using oData
you can enable oData from an entity list and access that via JS - docs.microsoft.com/.../liquid-filters
------------
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
Siv Sagar
149
Super User 2025 Season 1
Muhammad Shahzad Sh...
61
Most Valuable Professional
Daivat Vartak (v-9d...
53
Super User 2025 Season 1