cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Nttdocomo
Frequent Visitor

content Get field names and items

Is there a way to get these two contents in the CLI?

1 ACCEPTED SOLUTION

Accepted Solutions

This error is being generated due to TypeScript checking.  The Options property can be undefined so you need to account for that. Here are two possible options for you.

 

This one uses option chaining and the logical operator to set a default value if the property for Options does not exist.

var test: any[] = context.parameters.inputValue.attributes?.Options || [];

The second one allows the variable to be undefined or an array.  You will need to make sure to check the variable to make sure it's not undefined before you use it though.

var test: any[] |  undefined= context.parameters.inputValue.attributes?.Options;
 
I'm actually a little surprised you are not seeing the error before the build in Visual Studio Code. You may want to open your project one folder level higher so that the tsconfig.json file is seen by VS Code.
 
--Rick

View solution in original post

2 REPLIES 2
Nttdocomo
Frequent Visitor

I encountered an error using this code?

This error is being generated due to TypeScript checking.  The Options property can be undefined so you need to account for that. Here are two possible options for you.

 

This one uses option chaining and the logical operator to set a default value if the property for Options does not exist.

var test: any[] = context.parameters.inputValue.attributes?.Options || [];

The second one allows the variable to be undefined or an array.  You will need to make sure to check the variable to make sure it's not undefined before you use it though.

var test: any[] |  undefined= context.parameters.inputValue.attributes?.Options;
 
I'm actually a little surprised you are not seeing the error before the build in Visual Studio Code. You may want to open your project one folder level higher so that the tsconfig.json file is seen by VS Code.
 
--Rick

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (1,656)