Search code examples
integrationfrends

Return value from code statement in Frends process without assigning variable


In a Frends process, sometimes I just want to pipe the result of one C# statement into the next element, just like how tasks work, and I'd rather not pollute the scope with a variable that will only be used once.

I tried keeping "Assign variable" disabled on the C# statement element and returning a value as normal, but that throws an error. I would have expected to just be able to access the value using #result or #result[element name].

Is there any other way of doing it? Perhaps assigning your return value to some special hash reference that I haven't found?


Solution

  • When using a smaller code element you need to assign a variable if you want to return data from the code element, or as the docs put it

    A Code element that does not declare a variable will only return a String value indicating that it has been executed.

    You can work around this by modifying some previously defined variable, or by using bigger code element where you can run multiple lines of C# code.

    e.g. if you have code

    {
    int temp = 1;
    int temp2 = 2;
    
    return temp + temp2;
    }
    

    And assign it to variable foo like this

    enter image description here

    then only #var.foo is available afterward (temp and temp2 are not).