Result Path and Result Selector are employed to extract dynamic data from the state's result when the execution is successful.
Result Selector
Result Selector lets you retrieve and process the runtime data, enabling flexible and dynamic data manipulation within your application. With this, you can precisely control the relevant and essential parts of the state's result, excluding unnecessary data or modifying existing values as needed.
To implement the desired modifications, you define key-value pairs where each key represents a specific result modification. The corresponding values associated with these keys can be either static or dynamically derived from the state's result. By using the Result Selector, you can tailor the data to be sent to the Result Path based on your specific needs.
Consider the following JSON data received as an output of a task or function execution in a State:
{
"status": "success",
"message": "Employee onboarded successfully.",
"emp_id": "543",
"name": "Martin",
"department": "Product Management",
"joining_date": "2023-07-23",
"designation": "PM Associate",
"manager": "Jane Smith",
"location": "New York",
"salary": 75000,
"benefits": [
"Health Insurance",
"401(k) Plan",
"Paid Time Off"
],
"documents": {
"offer_letter": "offer_letter_EMP12345.pdf",
"employment_contract": "empcontract_EMP12345.pdf",
"tax_forms": "tax_forms_EMP543.pdf"
}
}
Suppose the employee_department and offer_letter alone in this result is expected in the next state, here's how it can be achieved using the Result Selector in Code view:
{
"get_employee_details": {
"type": "circuit",
"next": "End",
"start": true,
"circuit_id": "<Circuit_Name>",
"result_path": "$.Output",
"result_selector": {
"employee_department": "$.department",
"letter_of_intent": "$.documents.offer_letter"
}
}
}
The given definition of the Result Selector produces the following output:
"output": {
"employee_department": "Product Management",
"letter_of_intent": "offer_letter_EMP543.pdf"
}
Only the necessary information is extracted from the result and passed as output.
For configuring JSON Path expressions in the Result Selector, refer to the Context Object.
Result Path
Result Path enables you to adjust the output of a state. Within the Result Path, you can specify the state's input, the state's result, or a combination of both as the state's output. Essentially, you have the option to append the state's result to the JSON input given to the state and make alterations. You can then pass this modified JSON as the state's output to the next state for processing. It's important to note that if the Result Selector is configured, Result Path becomes mandatory.
Result Path is available for all the states except Branch, Wait, Success, and Failure.
If the Result Path is not specified, the state will discard the result and retain the original input.
For example, let the following JSON be the state input for your execution:
{
"org_name": "Global Solutions",
"employee_details": {
"name": "Martin",
"emp_id": "543",
"role": "PM Associate"
}
}
Let the state result received be the following:
"location": "New York"
To keep the state input intact and to append the state result to it, set result_path to $.location:
{
"get_employee_details": {
"type": "pass",
"next": "End",
"start": true,
"result_path": "$.employee_details.location",
"result": "New York"
}
}
This includes the state result with the actual input:
{
"org_name": "Global Solutions",
"employee_details": {
"name": "Martin",
"emp_id": "543",
"role": "PM Associate",
"location": "New York"
}
}
In the event of a failed execution, the data can be refined utilizing Error Path and Error Selector.