I’m currently passing in a selection of agencies via a list variable, and I want all the values passed in by default to be checked. Currently the JSON file list every single variable as true.
Today a new agency joined the list, which got me thinking it wouldn’t be practical to update this list each time there’s a new agency. Is there a way to just set all values to be checked by default without the need to change my script? I’m currently drawing the list of agency from an excel so there’s no need to change the script when I amend the list.
To handle dynamic updates where you want all values to be checked by default without manually updating the JSON each time a new agency is added, you can approach this in a few ways. Here’s how you can do it efficiently:
Dynamic JSON Generation with Default Values
Instead of hardcoding the JSON values, you can dynamically generate the JSON with all values set to true based on the agency list from your Excel file. Here’s how you can do this:
Read the List of Agencies from Excel:
Use UiPath to read the list of agencies from your Excel file into a DataTable.
Create JSON with Default Values:
Use UiPath activities to generate a JSON string where all agencies are set to true.
Detailed Steps in UiPath
Read Agencies from Excel:
Excel Application Scope:
FilePath: Path to your Excel file.
Read Range:
SheetName: The sheet where your agencies are listed.
Output: dtAgencies (DataTable)
Create a Dictionary with Default Values:
Assign Activity:
To: agencyDict
Value: New Dictionary(Of String, Boolean)
For Each Activity to iterate through the DataTable:
TypeArgument: System.Data.DataRow
Values: dtAgencies.RowsInside the loop:
Assign Activity:
To: agencyDict(row("AgencyName").ToString())
Value: True
Convert Dictionary to JSON:
Use the Newtonsoft.Json package to serialize the dictionary to JSON.
Thanks for the response but I found a more direct way to do this. I can just pass the dictionary into the form since all the values are already set to True. Was wondering if there’s actually a easier way to do by changing the parameters directly in the form designer instead of having to create a dictionary.