35.15.Sending data from view script into server side scripts
You can easily send some data from View Scripts into the Server Side Scripts. When is this useful? For example, user can select some item on the screen, you can send this selection into the server side scripts, retrieve some data, write a recipe to the PLC or do whatever action you need to do.
1. We will create a view with a button. Click on the button, in properties select Commands and On Click In On Click command select Script and create a new function sendData.
2. Now open a view script and fill in sendData function. You can use drag and drop from Help as shown on the picture:
4. Once we have our part in view script ready, let’s go to our server side script. Open main.js
5. You can see there is already prefilled function called dataFromViewScripts this function received all data you send from view scripts. Fill in the function:
6. You can see that our function receives data, multiplies the value in received object by 2 and sends the object back.
7. Now when you load your project into myPRO or myBOX, when you press a button, your object is sent to the server, received by the function myscada.dataFromViewScripts and then sent back to view script.
In the provided dialog, please select our created data-log by its name. Then fill in the time stamp of the record. Under this time, the record will be saved. Time has two parts, first is UTC time in seconds (since 1.1.1970) and second part is the number of milliseconds. If you leave the default values, new record will be logged at the time when your script is called.
Finally, fill in the values for each defined tag in data-log. Those can be hard coded values or variables.
Once you are done, press OK button. myDESIGNER will automatically create a code for you and insert it into the edited script.