Creating a workflow

Ops Center Automator User Guide

Version
10.8.x
File Size
3.6 MB
Audience
anonymous
Part Number
MK-99AUT001-14

Creating a workflow enables you to connect processes that you want to automate by using ServiceNow. To run the Ops Center Automator service in a workflow, extend or include the sub-workflow (Invoke Automation Service) into an upper layer workflow and insert the parameter mapping step. In this sub-workflow, you define the common process sequences of running a service and reporting task status. Also, you can use the AutomationClientLibrary to include additional functions.

The following table shows the input service parameters to be specified when using the workflow integration.

Name Type Description Maximum length Default value Required/Optional
Service Instance ID String Specify the instance ID of the service to submit. 256 ${workflow.scratc hpad.serviceInst anceID} Required
Request Parameters String Specifies the input properties of the service to submit. 102400 ${workflow.scratc hpad.requestPara meters} Optional
Task Settings String Specify the task run schedule. If not specified, the task is run immediately. 102400 ${workflow.scrc hpad.taskSetting s} Optional
REST Message Name String Specify the name of the REST Message for which the Ops Center Automator endpoint is set. 256 ${workflow.scratc hpad.restMessage Name} Required
Use Common Services String Speccify whether Common Services is used for user authentication. 256 ${workflow.scratch hpad.useCommonSe rvices} Optional
Common Services REST Message Name String Specify the name of the REST Message for which the Common Services endpoint is set. 256 ${workflow.scratc hpad.commonServi cesRestMessageNa me} Optional

See Create a workflow in the ServiceNow product documentation for instructions.

Sample workflow

The following is an example of a workflow that calls an Ops Center Automator service that incorporates the Invoke Automation Service sub-workflow.

.

In this workflow, the following actions are run as a series of flows:

  • approval processing
  • mapping user input to Ops Center Automator service request parameters
  • running an Ops Center Automator service and receiving a result confirmation
  • subsequent processing according to the result


Input for Invoke Automation Service sub-workflow

In the Invoke Automation Service sub-workflow, set the input service parameters.

  • REST Message Name
  • Request Parameters
  • Service Instance ID
  • Task Settings

In the sample workflow Manipulate Input step, user input values are mapped to variables of the Invoke Automation Service flow. The sample code is as follows:

workflow.scratchpad.serviceInstanceID = current.variables.had_service_instance_id; //Service Instance ID
workflow.scratchpad.restMessageName = current.variables.had_rest_message_name; //REST Message Name
workflow.scratchpad.useCommonServices = true; //Use Common Services
workflow.scratchpad.commonServicesRestMessageName = current.variables.common_services_rest_message_name; //Common Services REST Message Name

function RecordAccessor(ticket) {
	this.setRecord(ticket);
}

RecordAccessor.prototype = {
	setRecord: function(ticket) {
		this._ticket = ticket;
	},
	getSysId: function() {
		return this._ticket.sys_id;
	},
	getVariable: function(key) {
		return this._ticket.variables[key].toString();
	},
	getVariables: function() {
		return this._ticket.variables;
	}
};
workflow.info("Manipulating input from service request");

var recordAccessor = new RecordAccessor(current);

/* Settings of Automator service input parameters(*) */
var requestParams = {};
requestParams["VolumeLabel"] = recordAccessor.getVariable("VolumeLabel"); //String type parameter setting example
requestParams["StorageSystem"] = JSON.stringify({“storageDeviceId”: recordAccessor.getVariable("StorageDeviceId")}); //File type parameter setting example
/*~~~~~~~~~~~~~~~~~*/
/* (Set as much as required) */
/*~~~~~~~~~~~~~~~~~*/
workflow.info(JSON.stringify(requestParams, null, 2));
workflow.scratchpad.requestParameters = JSON.stringify(requestParams);

In requestParams, the required Ops Center Automator parameter Key and Value are set. You can also specify the service run schedule as a task setting. For details on the built-in service parameters and task settings, see "Submitting a service" in the Hitachi Ops Center Automator REST API User and Reference Guide.

After running the Ops Center Automator service and obtaining the result, you can implement post-processing according to the use case, such as updating the ticket as is shown in the sample workflow.

Output from Invoke Automation Service sub-workflow

The output of the Invoke Automation Service sub-workflow includes the following:

  • status: Completed, Failed, or Canceled.
  • data: JSON format data of the Ops Center Automator service output property values obtained by using the Ops Center Automator "Getting a list of property values" REST API.
  • message: Error message (only when an error occurs).

You can easily obtain the Ops Center Automator service output property values provided in JSON format to use with a method defined in the AutomationClientLibrary. The sample code is as follows:

var result = workflow.scratchpad.hadresult;

var allocatedVolume = AutomationClientLibrary.findPropertyByValue (result.data, 'keyName', 'LUNPathConfigurationInformation').value;  // Pick up value from JSON data by specifying property keyName

workflow.info("Details of added volumes: " + JSON.stringify(allocatedVolume,null,2));

current["work_notes"] = JSON.stringify(allocatedVolume, null, 2);