InObject - chart function
The InObject() chart function evaluates whether or not the current object is contained inside another object with the ID specified in the function argument. The object can be a sheet or a visualization.
This function can be used to show the hierarchy of objects in a sheet, from the top-level sheet object to visualizations nested within other visualizations. This function can be used alongside the if and ObjectId functions to create custom navigation in your apps.
Return data type: Boolean
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
|id_str||A string value representing the ID of the object being evaluated.|
The sheet ID can be obtained from the app URL. For visualizations, use the Developer options to identify the object ID and the text string of the object type.
Do the following:
In analysis mode, add the following text to your URL:
Right-click a visualization and click Developer.
Under Properties, obtain the object ID from the dialog header, and the object type from the "qType" property.
This function can give unexpected results when invoked in an object (for example, a button) inside a container which is a master item. This limitation also applies to filter pane master items, which are containers for a number of listboxes. This is because of how master items use the object hierarchy.
InObject() is often used in combination with the following functions:
|if - script and chart function||The if and ObjectId functions can be used together to create conditional expressions. For example, visualizations might achieve conditional coloring through expressions using these functions.|
|ObjectId - chart function||Similar to if, ObjectId is also used with InObject to create conditional expressions.|
Example 1 – Basic functionality
The following basic example demonstrates how to determine whether an object is contained inside another object. In this case, we will be checking if a Text & image object resides in a sheet object using the ID of the sheet as an argument.
Do the following:
Open a new sheet and drag a Text & image chart onto the sheet.
In the properties panel, click Add measure.
Click to open the expression editor.
Paste the following expression into the dialog:
Modify the expression to include the ID of your sheet as a string between the parentheses.
For example, for a sheet with ID 1234-5678, you would use the following:
The value -1 is displayed in the chart, indicating that the expression was evaluated to be true.
Example 2 – Objects with conditional colors
The following example demonstrates how to create custom navigation buttons showing different coloring to indicate the sheet that is currently open.
Start by creating a new app and opening the Data load editor. Paste the following load script into a new tab. Note that the data itself is a placeholder and will not be used in the example content.
Transactions: Load * Inline [ id,date,amount 8188,'1/19/2022',37.23 8189,'1/7/2022',17.17 8190,'2/28/2022',88.27 8191,'2/5/2022',57.42 8192,'3/16/2022',53.80 8193,'4/1/2022',82.06 8194,'4/7/2022',40.39 8195,'5/16/2022',87.21 8196,'6/15/2022',95.93 8197,'7/26/2022',45.89 8198,'8/9/2022',36.23 8199,'9/22/2022',25.66 8200,'11/23/2022',82.77 8201,'12/27/2022',69.98 8202,'1/1/2023',76.11 8203,'2/8/2022',25.12 8204,'3/19/2022',46.23 8205,'6/26/2022',84.21 8206,'9/14/2022',96.24 8207,'11/29/2022',67.67 ];
Creating the visualizations
Load the data and create two new sheets. Title them Sales 2022 and Sales 2023 respectively.
Next, build two button objects that will be used to navigate between the two sheets.
Do the following:
Add two Button objects to the sheet.
Under Appearance > General, set the Label of each button to Sales 2022 and Sales 2023, respectively.
- Arrange the buttons to match the following image.
Select the Sales 2022 button, and expand Actions and navigation in the properties panel.
Click Add action and under Navigation, select Go to a sheet.
Under Sheet, select Sales 2022.
Repeat this button action setup to link the Sales 2023 button to the Sales 2023 sheet.
Convert the buttons to master items by right-clicking them and selecting Add to master items.
You can now copy each button and paste it in the Sales 2023 sheet, using the same size and arrangement on the sheet.
Creating conditional colors
Next, configure the buttons so that they will be blue if they are linked to the currently open sheet, and light gray if linked to the sheet that is not open.
Do the following:
Open the Sales 2022 sheet and obtain the sheet ID from the URL. Keep the Sales 2022 sheet open.
Click the Sales 2022 button master item and select Edit in the properties panel.
Under Appearance > Background, select to color the button By expression.
In Expression, paste the following text:
=if(InObject(''), Blue(), LightGray())
Between the parentheses in the above expression, paste the sheet ID for the Sales 2022 sheet.
The button is now configured to turn blue when the Sales 2022 sheet is open, and light gray when it is not open.
Repeat the above instructions for the Sales 2023 sheet, linking the Sales 2023 button master item to the Sales 2023 sheet ID.
Each sheet should now have two buttons indicating the currently open sheet with the color blue.