Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

JsonPath in Key for Set Variable not resolving #3829

Open
josephjacobmorris opened this issue Oct 31, 2023 Discussed in #3827 · 2 comments
Open

JsonPath in Key for Set Variable not resolving #3829

josephjacobmorris opened this issue Oct 31, 2023 Discussed in #3827 · 2 comments

Comments

@josephjacobmorris
Copy link

Discussed in #3827

Originally posted by josephjacobmorris October 30, 2023
Task Definition

{
  "name": "update_task_migrate_0",
  "taskReferenceName": "update_task_migrate_0",
  "inputParameters": {
    "${task_migrate_0.output.refId}": "${task_migrate_0.output}"
  },
  "type": "SET_VARIABLE",
  "startDelay": 0,
  "optional": false,
  "asyncComplete": false
}

During execution the key is not getting resolved while the value is getting resolved

{
  "${task_migrate_0.output.refId}": {
    "subWorkflowId": "cab266f5-43b1-450e-a59b-5f35ca696bcd",
    "taskId": "bc4468fd-f168-4842-9bde-8a681d1a2aac",
    "refId": "buylistproduct#935"
  }
}

Can you help me understand what is the issue ?
I tried going thru the code and found that in ParameterUtils , we are only replacing the values and not the keys as shown in below snippet.

private Map<String, Object> replace(
            Map<String, Object> input, DocumentContext documentContext, String taskId) {
        Map<String, Object> result = new HashMap<>();
        for (Entry<String, Object> e : input.entrySet()) {
            Object newValue;
            Object value = e.getValue();
            if (value instanceof String) {
                newValue = replaceVariables(value.toString(), documentContext, taskId);
            } else if (value instanceof Map) {
                // recursive call
                newValue = replace((Map<String, Object>) value, documentContext, taskId);
            } else if (value instanceof List) {
                newValue = replaceList((List<?>) value, taskId, documentContext);
            } else {
                newValue = value;
            }
            result.put(e.getKey(), newValue);
        }
        return result;
    }

Is this being done due to some reason which I am not aware of?
Alternative approaches would also be appreciated .

@manan164
Copy link
Contributor

manan164 commented Nov 3, 2023

Hi @josephjacobmorris , This is expected behavior. Feel free to contribute to having functionality to replace keys. We will be happy to review it.

@josephjacobmorris
Copy link
Author

Hi @manan164 , Thanks for update :)
Sure , I have implemented in my fork , will raise a PR once I am done with my deliverables

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants