4

How can I use function arguments in a Coldfusion thread? I do not understand why I get the following error:

Element SOMEID is undefined in ARGUMENTS.

A simplified example of my code.

public any function createSomeEntity(required numeric someId) {     
    thread action="run" name="someThread" {
        var result = someFunction(someId = arguments.someId);
        // some logic
    }
    thread action="join" name="someThread" timeout="5000";
    
    if (someThread.status != "COMPLETED") {
        // action 1
    } else {
        // action 2
    }
}       
rrk
  • 15,677
  • 4
  • 29
  • 45

1 Answers1

7

You need to pass the variable as attribute for to the thread, thread cannot access the argument scope.

thread
    action="run"
    name="someThread"
    someId = arguments.someId
    ^^^^^^^^^^^^^^^^^^^^^^^^^
{
    result = someFunction(someId = attributes.someId);
                                   ^^^^^^^^^^
    // some logic
}
rrk
  • 15,677
  • 4
  • 29
  • 45
  • Thank you very much! I don't know why, but I didn't find this in CF documentation. – Roman Kharitonov Sep 24 '20 at 17:17
  • Could you please answer another question, please? How can I use the result variables in // action 1 section? – Roman Kharitonov Sep 24 '20 at 17:18
  • 3
    Just ignore my last question, I found the answer to it here - https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applications/using-coldfusion-threads/using-thread-data.html I should use Thread scope (`Thread.result`) instead of var and then call the variable as `someThread.result` – Roman Kharitonov Sep 24 '20 at 17:34