Dear Community User! We will start the migration process in one hour.
The community will be then in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 

WebIQ variable

WebIQ variable

junweilew
New Poster

Hi all,

I am currently facing issues setting the variable that I have manually created in webiq to the value from input field of webIQ. I am using a button to run the script. Any idea? Thank you!

6 REPLIES 6

webiq-sk
Frequent Contributor

I don't understand what you did exactly and what you are trying to achieve.

"setting the variable that I have manually created in webiq to the value from input field of webIQ" -> that sets the connected item value automatically, i.e. you don't set an item to a value from an input field because the input field itself should be connected to the item to set and does that automatically when the user enters a different value and leaves the field.

"I am using a button to run the script." -> is this a custom UI Action? There's also the UI action to write an item value.

If you describe what you want to achieve I might be able to provide a suggestion on how to do that with WebIQ.

Hi, sorry for the confusion.

So, I am generating data from node-red. WebIQ is displaying the 5 variables from node-red; flow, diff press, x, y, z.

I want to use a button to capture the data. I also created another set of variables as seen in the "Captured Data.png" to store the captured data. Thus, when i click onto the button the values of the variables is being stored in another set of variables. 
In the "UI action for te button" is my code for it, but i dont know if i am doing it correctly.

webiq-sk
Frequent Contributor

Your code is half-way correct. You're reading item values using readDirect which is the correct way of doing this.

However, you cannot simply "assign" values to item variables returned expecting that the pure assigment of variables in JavaScript will create a new server request automatically that updates the variables.

After reading item values using readDirect you must to use writeDirect to write the values to the other items - please see our Scripting Demo for examples on that.

Of course you don't have to read values you're not writing to you you should remove the variables to write to.

I am still a bit confused here. Could you explain it to me with some examples of writeDirect? Where can I access the examples for writeDirect

junweilew_0-1707210717275.png

Is this the correct way?

 

webiq-sk
Frequent Contributor

I mentioned the Scripting Demo before which you can download right from inside WebIQ Designer - this contains an example:
https://demo.smart-hmi.com/scripting-demo/

Here is some example code from the demo:
https://demo.smart-hmi.com/scripting-demo/js/custom-libs/ui-actions/demo-item-writedirect.js

To avoid confusion I'd not name both array `values`

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist