Possible to return an object with an RPC instead of an string?

Dear community,

I know that usually a rpc returns an output like this:

...
"output": {
  "label": "any label string",
  "value": "any value string"
}

But I tried to output an object instead like this.

"response": {
        "limit": 100,
        "iterate": "{{body.metadata.tables}}",
        "output": {
            "label": "{{item.name}}",
            "value": {
                "name": "{{item.name}}",
                "id": "{{item._id}}"
            }
        }
    }

I use this rpc to populate a select option in my Mappable parameters and this is working fine.

{
        "name": "table",
        "label": "Table Name (Source)",
        "type": "select",
        "required": true,
        "mode": "edit",
        "default": "Table1",
        "options": {
            "store": "rpc://tableNames",

In the Communication it is working also fine. I can access both values with:

  • {{parameters.table.id}}
  • {{parameters.table.name}}

Now here comes the problem:
Every time I reopen the module, the select value is blank.

image

I can still execute the module and the value is still working, but for the user this is quite confusing.

To summarize:

returning an object instead of a string with an rpc to populate a select option is working except that the selected value is not shown after a re-opening of the module.

Does anybody has a solution for this problem?
Best regards
Christoph

I tried a lot of things but in the end, I don’t find an easy solution.

The only way to solve this, looks like I pass a string that I can split into an array.

The rpc will look like this:

"output": {
  "value": "VALUE A___VALUE B",
  "label": "my label"
}

In Communication I experimented with calls like this but I couldn’t get the value after splitting it into an array.

"{{split(parameters.table;'__')[1]}}"

Therefore I wrote a short IML function:

// get a value from an array-string (a array-string is a string, that looks like an array)
// this is necessary because rpc can only pass one value and not an object. 
// therefore I pass multiple values in one string separated with __

function getAS(input, position, separator = "__") {
  if ( typeof(input) === "string" && input.includes(separator)){
    const array = input.split(separator);
    return array[position];
  }
  return input
}

Then I can use command in communication:

"{{getAS(parameters.table, 1)}}".

I hope this is working. I will keep you updated.

This IML function is working as expected.

Still, I observed that it is also necessary to set the input select field to editable: false.
Otherwise, the users could activate Map and enter the label instead of the value manually. But this would lead to errors with the execution.

My input field looks like this:

    {
        "name": "table",
        "label": "Table Name (Source)",
        "type": "select",
        "required": true,
        "mode": "edit",
        "editable": false, // important because it requires array-like string from rpc.
        "help": "**Hint:** mapping is not available for this selection in this module.",
        ....

Nevertheless, I am satisfied with this solution because the users don’t see the complexity and the selection is not empty anymore after re-opening.

Hey there @Christoph_Dyllick-Br :blob_wave:

I have to say that I’m truly impressed with the great work you’ve done on your app. It is so inspiring to see you figuring out solutions!

Thank you very much for leading us through the process and sharing the important details. We really appreciate it, because this way we keep our community tidy and healthy.

Keep up the amazing job! :meow_heart_bongo:

1 Like