web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Trying to conditionally set view of a subgrid based on Option set on form

(0) ShareShare
ReportReport
Posted on by 387

Hi I'm trying to get a subgrid on my form to change views depending on a option set selection.

I am using

function fnChangeViewOfSubgrid(ExecutionContext) {
	"use strict";
	var oFormContext = executionContext.getFormContext();
	var Practice = oFormContext.getAttribute("new_practices").getValue();
	var viewSelector = oFormContext.getControl("Opportunities").getViewSelector();
	if(Practice != null) {
		Switch(Practice) {
			Case 100000005: var PracticeView = {
				entityType: 1039,
				id: "4F671F67-9D35-EB11-A813-000D3A347311",
				name: "Engineering Practice - Active Opportunities"
			};
			viewSelector.setCurrentView(PracticeView);
			default: var PracticeView = {
				entityType: 1039,
				id: "00000000-0000-0000-00AA-000010003006",
				name: "Closed Opportunities"
			};
			viewSelector.setCurrentView(PracticeView);
		}
	}
}

But it isn't working.

I've tried various online javascript validators but they are saying I'm missing semicolons? But I don't see it?

Does anyone else see what I'm doing wrong or have a better way?

Thanks,

Terry

I have the same question (0)
  • Verified answer
    Fubar Profile Picture
    2,756 on at
    RE: Trying to conditionally set view of a subgrid based on Option set on form

    Switch and Case should be all lower switch and case

    and you should break; at the end of each case block (unless you want both case and default code blocks to run)

  • Mattw112b Profile Picture
    387 on at
    RE: Trying to conditionally set view of a subgrid based on Option set on form

    Thanks,

    Turns out I had other capitalization issues too...

    Working now

    function fnChangeViewOfSubgrid(executionContext) {

    var oFormContext = executionContext.getFormContext();

    var SelectedPractice = oFormContext.getAttribute("new_practices").getValue();

    var viewSelector = oFormContext.getControl("Opportunities").getViewSelector();

    if (SelectedPractice !== null) {

    switch (SelectedPractice) {

    case 100000005:

    var PracticeView = {

    entityType: 1039,

    id: "4F671F67-9D35-EB11-A813-000D3A347311",

    name: "Engineering Practice - Active Opportunities"

    };

    viewSelector.setCurrentView(PracticeView);

    break;

    default:

    var PracticeView = {

    entityType: 1039,

    id: "00000000-0000-0000-00AA-000010003006",

    name: "Closed Opportunities"

    };

    viewSelector.setCurrentView(PracticeView);

    break;

    }

    }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 149

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 132

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 123 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans