Example
Learn how to write code for this action with the help of webMethods Integration conventions.
Request module: You can make simple HTTP calls to the third-party applications by using this module. You can useGET,POST,PUT,DELETE, orPATCHmethod in the request module to do specific actions. You need to define this module at the start of the code by using therequire()function.this.id: Specify a unique ID for this action.this.label: Specify the name that you want to use as a title for this action.
this.input
-
title (required): This key is used to specify the title of the form. -
type (required): This key is used internally. The value for this key must always be set to the object and must not be changed. -
properties: Under properties, specify the input fields (and validation conditions, if any) that you want in the form. Different types of input fields are listed:- String
- Object
- Array
- Any
-
PagerDuty Connection (String) - Mandatory
-
Service Integration Key (String) - Mandatory
-
Description (String) - Mandatory
-
Details (String) - Optional
Define all these fields inside the properties key:

You can use OAuth exposed by webMethods Integration to add an authorization field for your custom action. Click here to know more about it.
It is important to set the value of minLength to 1 for all the mandatory input fields. It ensures that the user does not leave any mandatory field blank. In the example, the value of minLength is set to 1 for the mandatory Title field. The user must enter input in the Title field or otherwise webMethods Integration produces an error.
this.output
In this block, you need to define the output parameters that is returned by the action. All the fields that are defined here must follow the JSON schema structure. It contains two main keys for which you need to assign values.
-
type: This key is used internally. The value for this key must always be set to 'object' and must not be changed. -
properties: This key is used to define all the output parameters that are returned by the action. The different types of output parameters are listed:-
String
-
Object
-
Array
-
Any
-
The sample action returns the following output parameters:
-
Incident status
-
Incident message
-
Incident key
Define all these output parameters inside the properties key as shown:

this.execute
In this block, you need to write the entire action logic that is run inside the webMethods Integration engine. The
function that is defined in this block has two function parameters: input and
output.
-
input: This parameter will fetch and handle the input data that is provided by the user in the action form. -
output: This parameter informs the webMethods Integration engine that the action execution is completed. -
request module: As mentioned earlier, this module helps you to make HTTP calls to third-party applications. In order to do that, you need to provide values for following keys:-
Headers: Pass the required values to create a connection. -
Method: Specify the HTTP method to be used to make an API call. -
URL: Provide the URL to which you want to make an HTTP request. -
Error handler: Specify error handler functionfunction (err,response,body)for your action. If the action throws an error, it should return output(err), and if the action is executed successfully, it should returnoutput(body).
-
You can learn more about request module https://github.com/request/request.

After you have completed writing the last block, Compile it. The errors, if any, are highlighted in the console. When the action is compiled successfully, you see the action input form in the integration window:
Click Save to create the custom action. The custom action is then added under the Custom tab.
Error Description
webMethods Integration returns an error if any of the mandatory keys are not included in your code.
For example, the title key is not included in the this.input block. Since the
title is a mandatory key, the custom action returns an error when you compile the code. The error
message is mentioned:

The error message is structured as mentioned:
-
Block in which the error is encountered: Since the error is present in this.input block, the error message shows Input.
-
Type of error: It states the type of the error encountered.
-
Error description: Since the title key is not included, it shows the relevant error description for the same.
-
Path: It shows the path where the error occurred. Since the this.input block is defined in the root of the code, the path for this particular error returns [].
Similarly, if you do not include type key for Status output
field under properties key in the this.output clock, webMethods Integration returns an
error when you compile the code.
Log Data
You can capture the log data of the custom actions by using $log() inside the
this.execute block. For example, if you want to capture the log details of the
input data in the custom actions, add $log("formdata " + JSON.stringify(formdata));
after the formdata section.
