Skip to content

Communication Between Different Applications

Background

In a project with two applications, when a user is created in Application A, the same user needs to be synchronously created in Application B. This requires pushing an application event when a new user is created in Application A, and creating a listener in Application B to monitor the application event sent by Application A, triggering automation to synchronously create the same user.

Implementation Steps

We can now implement this function through the following steps:

  • In Application A: User Data Table >> Table Settings >> Toolbar >> Toolbar Controls, create a new Create Button

    Click Edit to enter the creation button editing page, execute the operation, and select Call Automation

    Automation Program (Create User and Synchronize Hospital Member): Open Record Creation Page -> Code Snippet (Add Application Member) -> Publish Application Event (Hospital Member)

    Overview of the automation program:

    For the code snippet (Add Application Member), please refer to 【Application Layer Listening】Login

    Select the already configured "Hospital Member" for publishing the application event, and select the form object formRcord returned by "Open Record Creation Page" as the event content

  • Next, let's talk about how to create the "Hospital Member" application event in Application A (One-Stop Service).

    Global Settings >> Listener >> Event Definition, create a custom event

    Name the event "Hospital Member" with the identifier "hospitalUserCreate". Please remember it and copy it.

  • Now let's switch to Application B (Hospital End). The first thing is to establish a dependency relationship between Application B and Application A. Go to Global Settings >> Advanced Settings >> Dependent Applications, and select Application A (One-Stop Service)

  • Next, enter Global Settings >> Listener >> Create Listener

    Fill in the event ID with the identifier of the "Hospital Member" application event that we copied earlier, and execute the already prepared automation

  • The automation program (Automatically Create Hospital Member) is as follows:

    Click Add Parameter, select Listener Event as the input parameter, and name it eventValue

    Print eventValue, the JSON data is as follows:

    javascript
    "eventValue":{
      "content":{
          "appDefineId":"com.gyytest.MyApp",
          "appId":"g0j4gmx7mbwr4",
          "companyId":"g09aj7cus3d8s",
          "id":"hospitalUserCreate",
          "payload":{
            "name":"CN1000",
            "id":"qcyha8qtg9bh5"
           }
      },
      "id":"app.postevent"
    }
    
    // The parameters we need are in payload

    Set the username field expression to $

    Finally, save and publish, and the function will be implemented

Effect

  • Add a new user in Application A

  • A record with the same username will be automatically added in Application B