Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Navigate to the workspace "pjstips".
  • Click New/Module File.
  • Click Edit/Source, to bring up the Source view.

  • Clear the current default code, and enter the code below.

  • Code Block
    languagejs
    {
      "routines": [
        {
          "name": "routine1",
          "inputs": [
            {
              "type": "decimal",
              "ibmiLength": 4,
              "name": "custno",
              "ibmiDecimals": 0
            }
          ],
          "outputs": [
            {
              "type": "string",
              "ibmiLength": 30,
              "name": "name"
            }
          ],
          "steps": [
            {
              "text": "Consume REST service",
              "answers": {
                "plugin": "Custom:web-service",
                "uri": "http://localhost:8081/run/pjstips/pjstips_02_3",
                "method": "POST",
                "headers": "{\"Content-Type\": \"application/x-www-form-urlencoded\"}",
                "body": "{\n  \"custno\": input[\"custno\"]\n}",
                "json": true,
                "auth": "",
                "capture_response": true,
                "capture_on_error": false,
                "capture_as": "Value",
                "specific_property": "",
                "destination": "Work variable",
                "work_variable": "myres"
              }
            },
            {
              "text": "Set Module output",
              "answers": {
                "plugin": "Program Data:set-module-output",
                "module-output-values": {
                  "name": "myres[\"name\"]"
                }
              }
            }
          ]
        }
      ]
    }


  • Click Edit/Design, to bring up the Design view.
  • If needed, in the "Consume REST service" step, change the Endpoint URL to point to the correct host/port.
  • Click Home/Save As, and save as pjstips_04_1.module.json.
  • You've created a low-code module, as shown below, with a routine named "routine1" that:
    • Takes an input parameter of "custno".
    • Uses plug "Consume REST service" to issue a POST request to URL http://localhost:8081/run/pjstips/pjstips_02_3 (created in a previous example).
    • The input "custno" is specified in the "body" of the POST request.
    • The returned JSON object from the REST web service is saved in a work variable named "myres".
    • The value of myres["name"] is used to set the output value output["name"].
    • But, it has a bug; we'll learn how to debug this problem.

...