13
Views
8
Comments
Mobile: get a value from JavaScript, an output var into the mainflow locale variable
Question

How do I get a value out of JavaScript via an Outputvariable into the mainflow in a local variable of a screen or the input variable of a screenfunction? Here is a screenshot:

Also in my code I call a screenfunction and the local var must filled with the outputvalue before the screenaction is called.


mvp_badge
MVP
Rank: #19

Hi,

Add an assign widget after the Javascript widget and assign the JavaScript1.OutputSkill to your newSkillName local variable.

Regards,

Daniel

Rank: #17692

I did, but it didn't work. Because the output info came after calling the screenaction where it was needed.

mvp_badge
MVP
Rank: #19
Rank: #17692

I re-did it and tested it again in another way and now I found out that the assign is called too early because the JavaScript (and the assign) is called onReady and the action is called via an EventListener on tab of the "Enter-key" (key 13).


Rank: #755

Ann Kemp wrote:

How do I get a value out of JavaScript via an Outputvariable into the mainflow in a local variable of a screen or the input variable of a screenfunction? Here is a screenshot:

Also in my code I call a screenfunction and the local var must filled with the outputvalue before the screenaction is called.


 Hi Ann,

As mentioned by Daneil, you are missing the assignment of the output variable after calling the java script in onReady event.

 

mvp_badge
MVP
Rank: #91

Hi Ann,

If you are trying to invoke/call a screen scope client action (with input parameter) from JS node follow the below mentioned approach

Syntax:

$actions.FunctionName(inputParameterValue);

See this sample app - SearchDropdownDemo 

function check(e) {
    if(e.keyCode === 13) {
        var ele = document.getElementById($parameters.ElementId);
        var inputValue = ele.querySelector('.choices__input--cloned').value;
        var selectedValue = ele.querySelector('.choices__item--selectable').innerText;
        
        console.log(inputValue, selectedValue);
        if(inputValue === '') {
            inputValue = selectedValue;
        }
        $actions.showSelectedValue(inputValue); // calling screen action with input parameter
    }
}

var ddEle = document.getElementById($parameters.ElementId);
ddEle.addEventListener('keyup', check);

Note: The assign node which is introduced after the JS node (in the OnReady action flow) to assign the JS output parameter won't get executed on the tap of key == 13 (Enter/Return Key) i.e. after the call of the keyup handler definition


Hope this helps you!


Regards,

Benjith Sam

Rank: #17692

I was thinking about that! But I thought: no, that's not possible, that's too easy. :)