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

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

 

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (54,594)