To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Events
Cancel

Custom Controls

Lesson 8: Server Actions

This lesson will discuss Server Actions, how to call on actions on the server from the client. What are they?

  • Simply put, they are just DataFlex procedures or functions with the addition of being able to call on them from the JavaScript client
  • this.serverAction(“MethodName”, aParams);
  • A server action can provide a return value that can execute a callback function
  • Important – they must be made available to the client by using one of the following:
  • WebPublishProcedure ProcedureName
  • WebPublishFunction FunctionName
  • These are typically used in the End_Construct_Object
  • Example code to show how it works
  • Example code to publish the server action
  • Example code to call on the server action from the JavaScript client

Demonstration

  1. Open WebMsgBuilder.js in a text editor
  2. Generate the serializer
    // Generate Serializer
    serializerMsgVT : df.sys.vt.generateSerializer([df.STring]),

  3. Implement the sendMessage function

    sendMessage: function () {      var tVt;
          var sMsg;

          sMsg = this.get_psValue();
          tVt = this.serializeMsgVT(this._aMsgParts);
          this.serverAction(“ReceiveMessage”, [sMsg], tVt, null);
    },

  4. Open cWebMsgBuilder.pkg in the DataFlex Studio
  5. Create a procedure for the receive message on the server
    Procedure ReceiveMessage String sMsg      tWebValueTree tVt
          String [] aMsgParts
          Get ptActionData to tVt
          ValueTreeDeserializeParameter tVt to a MsgParts
          Send OnReceiveMessage sMsg aMsgParts
    End_Procedure

  6. Add a user augmentable event to insert application logic at a later time
    { MethodType = Event }
    Procedure OnReceiveMessage String sMsg String [] a MsgParts
          //Augment with application logic
    End_Procedure

  7. Open Dashboard.wo in the DataFlex Studio
  8. Highlight the message builder code
  9. Open the object properties in the ‘Properties’ panel on the right by pressing CTRL+2
  10. Select the ‘Events’ tab
  11. The ‘OnReceiveMessage’ event is now shown. Double click it to add the event to the code.
  12. Add code to show a message box saying that the message has been received.
    Procedure OnReceiveMessage String sMsg String[] aMsgParts
          Forward Send On ReceiveMessage sMsg aMsgParts      
          Send ShowInfoBox sMsg “Message received!”
    End_Procedure

  13. Select the run icon from the top toolbar
  14. Open the application in the web browser: localhost/WebmessageBuilder/
  15. Refresh the screen (F5)
  16. Write something in the first field and press the ‘Add’ button or press ‘Enter’ to add it to the field.
  17. Press the ‘Send message to server button,’ and the ‘Message Received’ info box should appear with whatever was entered into the field.