cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

PCF Parameter Get values provided

I would like to check whether an optional parameter was provided or not (to render the control differently based on that)

I declared the parameter with these attributes:

of-type="SingleLine.Text" usage="bound" required="false"

 

How could I check in the Typescript code whether this Input parameter was bound or not?

 

I tried setting a variable in the Init method, like

this.myVariable = context.parameters.theParameter.raw || ""

 

But I didn't really see the value reflected, so not sure if Init method would be the right approach, or there is another way to obtain this metadata

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @rgomezArctictec , 

 

The property values can be static or dynamic (from a field): 

DianaBirkelbach_1-1604388622797.png

 

 

 

In case the customizing is done with a fixed value, then you have a type and a value, but the attribute is empty. So I still think that using property.type is safer than the property.attribute.DisplayName:

context.parameters.myParameter?.type === undefined

 In case the property.type is undefined, then it was not set.

 

Just in case it helps: the context.properties are not always provided in the init method. Sometimes you get them only in the "updateView" method.

 

Hope it helps!

 

Kind regards,

Diana

 

----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

4 REPLIES 4
Super User
Super User

Hi @rgomezArctictec , 

 

You could check if context.parameteres.<YOUR_PROPERTY>.type is null (or not SingleLine.Text). If so, the parameter was not defined in the customizing.

 

Kind regards,

Diana

 

Thanks Diana.

Actually I realized I was using the context variable in the wrong spot, once I put it in the correct Init method, I could do something like this:

 

myVariable = typeof (context.parameters.myParameter.attributes?.DisplayName) === "undefined" ? false : true

 

The reason is that context.parameters.myParameter was like an empty object {}, when not provided from the CRM form designer

 

Regards,

Hi @rgomezArctictec , 

 

The property values can be static or dynamic (from a field): 

DianaBirkelbach_1-1604388622797.png

 

 

 

In case the customizing is done with a fixed value, then you have a type and a value, but the attribute is empty. So I still think that using property.type is safer than the property.attribute.DisplayName:

context.parameters.myParameter?.type === undefined

 In case the property.type is undefined, then it was not set.

 

Just in case it helps: the context.properties are not always provided in the init method. Sometimes you get them only in the "updateView" method.

 

Hope it helps!

 

Kind regards,

Diana

 

----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Thanks Diana. Will use type property instead 🙂

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Check out the Power Apps Community Call for January 2021

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Users online (5,879)