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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Getting OptionSet value and setting Label Name based on Value

(0) ShareShare
ReportReport
Posted on by 90

Hi all, 

Could anyone help me understand why this code doesn't work? I'm trying to get the option set value of a field, and if it's "C", then set the label name to Celius. Here's my code:

function onload(executionContext) {
	debugger 
	if (executionContext == null)
		return;
	var formContext = executionContext.getFormContext();
	oppForm(executionContext);

};

function oppForm(executionContext) {
	debugger
	if (executionContext == null)
		return;
	var formContext = executionContext.getFormContext();
	var optionSetLabelName = formContext.getControl("dom_temperature");
	var optionSetChoice = formContext.getAttribute("dom_temperature").getText();
	console.log(optionSetChoice);
		
	if (optionSetChoice == null) {
		return;
	if (optionSetChoice == ("C")) {
		formContext.getControl("dom_temperature").setLabel("Celsius");
		}
		}
};

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    main reason is because the if condition checking the "C" text is inside the if condition checking the null, so it is never executed.

    This is your code a bit rewritten, you can start with this and debug if you have additional errors

    function onload(executionContext) {
    	oppForm(executionContext);
    }
    
    function oppForm(executionContext) {
    	var formContext = executionContext.getFormContext();
    	var optionSetChoice = formContext.getAttribute("dom_temperature").getText();
    	if (optionSetChoice == "C") {
    		formContext.getControl("dom_temperature").setLabel("Celsius");
    	}
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 98 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans