- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 12:09 PM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 05:27 PM
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.
- Once published, copy the 'Code snippet':
- 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:
source script example:
answer = (function transformEntry(source) {
return this.req_sysid; // return the value to be put into the target field
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 05:27 PM
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.
- Once published, copy the 'Code snippet':
- 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:
source script example:
answer = (function transformEntry(source) {
return this.req_sysid; // return the value to be put into the target field
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 01:04 PM
Hello @Jon23
I was trying to follow your instructions on how to create REQ/RITM using subflow. However, I got stuck at Action 1 and 2. What value do you pass in the requires Field? Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 02:12 PM
Hi @Jessica28 - The value may depend on what fields are required for those records on your instance.
I think OOB there are any for sc_request so just pick one. I would suggest the very least you would want something in the short description to help you identify the ones created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 08:26 PM
Thank you for your help @Jon23
I have a spreadsheet with 5 records. I used the following steps to create 5 requests.
- Created Data Source
- Created Transform Map
- Created Scheduled Import and attached the spreadsheet in it.
I would like to learn how to use “Flow Designer” to create 2 RITM for each of the requests and 1 task for each of the RITM.
For example:
- REQ0010240
- RITM0027227
- SCTASK0027324
- RITM0027227
- REQ0010241
- RITM0027225
- SCTASK0027564
- RITM0027225
Could you please provide suggestions how I can do this using Flow Designers?
Thank you