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

View solution in original post

Thanks Diana. Will use type property instead 🙂

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 (2,108)