cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rgomezArctictec
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."

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
DianaBirkelbach
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

 

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."

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."

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."

Thanks Diana. Will use type property instead 🙂

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Top Solution Authors
Users online (2,857)