cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
testasdfasfsafa
Advocate III
Advocate III

How to use Option Sets columns inside a Calculated text field?

Since I cannot find anything online, I'm hoping to tap into expert knowledge here...

 

I have a single entity with 3 options set columns in CDS, namely, Grade level, Genre, Format with their own internal IDs.

 

Goal

My goal is to have a text field with the concatenated corresponding label values such as (3 Writing Online) and not (100,003, 100,008, 100,010).  

 

In the calculated form, the intellisense doesn't even show the options sets 😞

 

Any tips or example would be appreciated...

3 REPLIES 3
Satish-Reddy
Continued Contributor
Continued Contributor

Easy with JavaScript. I wrote a function for you. You have to change the attribute names below to reflect your attributes.

You can call this function on the on-change event of the three option set attributes (adding the event handler). If you don't know how to upload JS & add an event handler, steps are described here:

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/walkthrough-write-y...

 

 

 

function ConcatLabels(executionContext) {
    var formContext = executionContext.getFormContext();    

    var gradeLabel= formContext.getAttribute("your_attribute_logical_name").getText();
    var genreLabel= formContext.getAttribute("your_attribute_logical_name").getText();
    var formatLabel= formContext.getAttribute("your_attribute_logical_name").getText();

var finalString = gradeLabel + genreLabel + formatLabel; // you can format your string here

//set the finalString to your attribute

formContext.getAttribute("your_attrbute_logical_name_to_set").setValue(finalString);

}

 

 

 

 

Please mark it as answer if my code helps.

 

Thanks
Satish Reddy
https://pascalcase.com

 

HSheild
Super User
Super User

Hi,

If you want a no-code approach then you can use CDS classic workflow. Trigger the workflow on change of your option set fields and use it to populate a text field that are the option set fields concatenated.

Details on classic CDS workflows are here https://docs.microsoft.com/en-us/power-automate/workflow-processes

Let me know if you need anymore help with this option.

Note, for the JavaScript solution provided previously. You might find that the onload trigger of the code will probably not work for you. You will need to trigger it on the onchange event of your option set fields.
Satish-Reddy
Continued Contributor
Continued Contributor

@HSheild  I second that. The handler has to be added on on-change events, not on-load. I am editing my post.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,077)