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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Unable to get the logi...
Power Apps
Unanswered

Unable to get the logical name of the optionset associated to a field

(0) ShareShare
ReportReport
Posted on by 8

Hello,

I have a model-driven app with several option sets being used. For example, "kdj_option1", "kdj_option2", and "kdj_option3".

I need to retrieve only the fields that use "kdj_option2" and "kdj_option3" using JavaScript.

Currently, I have the following code:

 

function test(executionContext) {
 var formContext = executionContext.getFormContext();
 formContext.ui.tabs.forEach(function (element) {
 if (element.getVisible()) {
 element.sections.forEach(function (section) {
 section.controls.forEach(function (control) {
 if (control.getControlType() === "optionset") {
 console.log(control)
 }
 });
 });
 }
 });
}

 

 

How do I modify this line 

 

if (control.getControlType() === "optionset") {

 

to only perform some code on the fields that do not use "kdj_option1"?

 

Thanks in advance

Categories:
I have the same question (0)
  • ebLott Profile Picture
    14 on at

    You can add an additional logical check, like this:

    if(control.getControlType() === "optionset" && control.getAttribute().getName() !== "kdj_option1")
    {
    console.log(control);
    }
  • paula12-29 Profile Picture
    8 on at

    This is not filtering out the logical names of option sets. This seems to be returning the fields that have a logical name of "kdj_option1".

  • ebLott Profile Picture
    14 on at

    @paula12-29 The if statement is filtering out the controls with the control.getAttribute().getName() !== "kdj_option1" argument. The console log is just a placeholder for example.

  • paula12-29 Profile Picture
    8 on at

    Maybe I am doing something wrong. But when I just include 

     

    if (control.getControlType() === "optionset") {
     console.log(control)
    }

     

    It returns 3 objects

     

    When I update the code to:

     

    if(control.getControlType() === "optionset" && control.getAttribute().getName() !== "kdj_option1") {
     console.log(control);
    }

     

    The same 3 objects are returned, even though "kdj_option1" is one of the option sets being used in one controls.

     

    Using the same code, if I change "kdj_option1" to the logical name of a column that is using this optionset, then I only (and correctly) get back 2 objects.

  • ebLott Profile Picture
    14 on at

    Try this without getAttribute:

    if(control.getControlType() === "optionset" && control.getName() !== "kdj_option1") {
     console.log(control);
    }

     

  • paula12-29 Profile Picture
    8 on at

    Unfortunately, still get back 3 objects, even when I remove getAttribute() from the line of code. Once again, if I change "kdj_option1" to the logical name of a column that is using this option set, then I get back the 2 objects.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard