Configure the JavaScript connector by writing custom script and validating custom classes and functions. Then you execute the script by providing values for the functions.
In the Toolbox pane, navigate to Connectors > JavaScript.
Drag the JavaScript connector to Global Objects in the Project Explorer pane.
Right-click the JavaScript connector in Global Objects and select
Configure.
The Script Editor window is displayed.
Enter the custom JavaScript in the Script pane.
Figura 1. Script pane in Script Editor
Opcional: Use the ServiceNow®Now Assist for code generation application as part your automation by using the Generate code button.
Use this button to generate AI code to write custom scripts quickly. The code is generated from a prompt based input.
Figura 2. Generate code button and prompt in Script Editor
To generate AI code, do the following steps:
Enter the input text in the prompt. Ensure that you provide a meaningful text input to generate the code of your choice. For example, generate code to find the process ID of an application.
Select Generate code. The JavaScript code is generated in the Script pane as per your input.Figura 3. Input text to generate code
Nota:
If you are not connected to an instance and select Generate code, a No instance is connected message displayed.
Select Validate.
If your custom script has any errors, it is displayed in the Errors pane. Resolve the errors and select Validate to check for errors again.Figura 4. Error pane for Script Editor
Click OK.
If you want to save the changes, select Yes. An error validation is performed again and the changes are saved. If you want to discard the changes, select No.
O que Fazer Depois
The custom script you created by using the JavaScript connector is now ready to be used in your automation.