Skip to content

Commit 0e56def

Browse files
committed
add example for checking if field exists
1 parent 6e5d1de commit 0e56def

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/ff-concepts/adding-customization/common-examples.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ final newProduct = ProductStruct(
201201

202202
#### Example 2: Accessing Properties of an Existing `ProductStruct` object
203203

204-
If you have an existing `ProductStruct` object (e.g., retrieved from a list of products), you can access its properties or return specific values back to the calling Action. Let's assume you have an Action that calls a Custom Action to retrieve a field value from the provided `ProductStruct` object.
204+
If you have an existing `ProductStruct` object (e.g., retrieved from a list of products), you can access its properties or return specific values back to the calling Action.
205+
206+
Let's assume you have an Action that calls a Custom Action to retrieve a field value from the provided `ProductStruct` object.
205207

206208
- **Returning a Single Field from ProductStruct**
207209

@@ -213,6 +215,18 @@ String? getProductName(ProductStruct product) {
213215
return product.name;
214216
}
215217
```
218+
219+
- **Checking if a Field Exists in a `ProductStruct` Object**
220+
This function determines whether the `ProductStruct` object contains a non-null value for a specific field, such as `description`. It returns `true` if the field exists and is not null, and `false` otherwise.
221+
222+
```js
223+
// Function to check if the description field exists in a ProductStruct instance
224+
bool hasDescription(ProductStruct product) {
225+
// Return true if the description is not null, false otherwise
226+
return product.description != null;
227+
}
228+
```
229+
216230
- **Returning a List of Review Comments from ProductStruct**
217231
218232
This function retrieves a list of review comments from the reviews field in the `ProductStruct`. The return type is `List<String>` as it returns a list of comments (or an empty list if there are no reviews).

0 commit comments

Comments
 (0)