Вопрос

I'm retrieving a value within an emitted code block that I would like to set an entity variable to. This is what I'm trying to do:

rule read_form {
    select when web submit "#loginForm"
    pre {
    }
    {
        emit <|
            function myFunction() {
                var myValue = 10;
            }
            myFunction();
        |>;
    }
    fired {
        set ent:myValue myValue;
    }
}
Это было полезно?

Решение

The way you have that architected won't work.

Here's why:

The select statement and pre block are evaluated on the Kynetx server when the event request first comes in. If the select statement evaluates to true, then the rule will return the emit JavaScript in the HTTP response to the raised event that came into the Kynetx server. Before that HTTP response goes back to the browser from the Kynetx server, the fired statement in the postlude will execute if you have an event that is going to be returned in the HTTP response. This means that the select statement, pre block and postlude blocks are evaluated and executed on the Kynetx server before the javascript is returned to the browser. So I guess the short answer is that the postlude has no idea what the value of 'myValue' is since the scope is very different (different machines).

Hope this helps. I probably should make a diagram explaining it a bit better but I have some critical work I need to get done tonight. Depending on your response I may come back to this question and answer it better later.

So, how could you make this work? You could accomplish what I think I understand you are trying to do by raising another event in your emitted javascript block passing the needed value. This would mean that the value would be available in the pre block and the postlude block of the rule that receives the raised event so you could save it in an entity variable.

You can also look at this blog post I did about raising events from JavaScript that might help shed some more light on the subject http://kynetxappaday.wordpress.com/2010/12/16/day-8-raise-web-events-from-javascript/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top