Transform map to create tasks and REQ and RITM

Giri6
Tera Expert

I need to create 70 service catalog tasks based on data from excel file. I need them to be part of one RITIM of REQ. Right now, I am creating REQ and RITM manually  and copying sysids and puttin in onBefore() trasform script as shown here.

Is it possible to automate to create REQ and RITM in transform map? I am thinking this how it can be done.

1. onStart() of transform script  create  REQ/RITM

2. Somehow pass those sysids of those two to onBefore of transform script

Appreciate your thoughts and any snippet on creating and also how I can share sysids to onBefore method.

--------

//onBefore()

(function runTransformScript(source, map, log, target /*/ ) {

    // Add your code here
    target.request_item = 'ff0ce23adbb31890de375278dc9619dd';
    target.request = '0fcbeaf6dbb31890de375278dc96191b';

})(source, map, log, target);

1 ACCEPTED SOLUTION

Jon23
Mega Sage

One solution is to use Flow designer to create your REQ/RITM. You then call this flow from your transform map via the onStart script and return the sysIDs of the REQ and RITM:

  • Create a Subflow in flow Designer
  • Add outputs to store the sysid of the REQ/RITM records it creates.
  • Create the required RITM/REQ record
  • Assign your Subflow outputs
  • Save and Publish the Subflow.

find_real_file.png

  • Once published, copy the 'Code snippet':

find_real_file.png

  • You should have something like this:
(function() {
	
	try {

		// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
		// sn_fd.FlowAPI.getRunner().subflow('global.my_req_ritm_subflow').inBackground().run();
				
		// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
		var result = sn_fd.FlowAPI.getRunner().subflow('global.my_req_ritm_subflow').inForeground().run();
		var outputs = result.getOutputs();

		// Get Outputs:
		// Note: outputs can only be retrieved when executing synchronously.
		var req_sysid = outputs['req_sysid']; // String
		var ritm_sysid = outputs['ritm_sysid']; // String
		
	} catch (ex) {
		var message = ex.getMessage();
		gs.error(message);
	}
	
})();

 

  • In your tansform map create an onStart script and paste in your code snippet.
  • Modify the '//Get Outputs' section so the variables are prefixed with 'this.'
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

        try {

            // Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
            // sn_fd.FlowAPI.getRunner().subflow('global.my_req_ritm_subflow').inBackground().run();

            // Execute Synchronously: Run in foreground. Code snippet has access to outputs.
            var result = sn_fd.FlowAPI.getRunner().subflow('global.my_req_ritm_subflow').inForeground().run();
            var outputs = result.getOutputs();

            // Get Outputs:
            // Note: outputs can only be retrieved when executing synchronously.
            this.req_sysid = outputs['req_sysid']; // String
            this.ritm_sysid = outputs['ritm_sysid']; // String

		} catch (ex) {
            var message = ex.getMessage();
            gs.error(message);
        }

})(source, map, log, target);

 

  • Create script field maps to use the 'this.variable' on the required target fields:

find_real_file.png

source script example:

answer = (function transformEntry(source) {

	return this.req_sysid; // return the value to be put into the target field

})(source);

View solution in original post

5 REPLIES 5

Giri6
Tera Expert

jwalton, Thanks for taking time to provide detailed instructions. It worked perfect by following instructions.  Code snippet is different though but since it is working it might be updated apis. Here is the snippet.

--------------

(function() {
    
    try {

        // Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
        // sn_fd.FlowAPI.startSubflow('global.createreqritm');
                
        // Execute Synchronously: Run in foreground. Code snippet has access to outputs.
        var outputs = sn_fd.FlowAPI.executeSubflow('global.createreqritm');

        // Get Outputs:
        // Note: outputs can only be retrieved when executing synchronously.
        var req_sysid = outputs['req_sysid']; // String
        var ritim_sysid = outputs['ritim_sysid']; // String
        
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
    
})();