Trigger subflow from Data Source/Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 08:43 PM
I have created a Custom (Load by Script) data source with the following script:
(function loadData(import_set_table, data_source, import_log, last_success_import_time) {
try {
var currentDate = new GlideDateTime(); //Get today's date/time
currentDate.addDays(-1); //Subtract 1 day to make it yesterday's date
var ydate = currentDate.toString(); //Convert it to text so we can manipulate it
var dt = ydate.split(' '); //Split at the space between date and time so we can get the date only
var textDate = dt[0].toString(); //Convert the date to text
//Use only 1 of the next 2 lines. The first with the static date is for the first run only.
//Once it has run, comment it and uncomment the second for all future runs
//var lastEdited = "2000-01-01T00%3A01%3A00Z";
var lastEdited = textDate + "T00%3A01%3A00Z"; //Combine it with the ISO 8601 format for time prepared for a url
//Make a rest call and get list of usersIDs that have been modified since last run
var rUpdate = new sn_ws.RESTMessageV2('HRPeopleSoft Photo', 'GET Updated Users');
rUpdate.setStringParameterNoEscape('LastModifiedDatetime', lastEdited);
rUpdate.setEccParameter('skip_sensor', true);
var userResponse = rUpdate.execute();
userResponse.waitForResponse(360);
var userResponseBody = userResponse.getBody();
var userHttpStatus = userResponse.getStatusCode();
// parse initial response
var userParser = new JSONParser();
var userResponseParse = userParser.parse(userResponseBody);
// get an array of IDs
var ids = userResponseParse.Response.Data.IDs;
// loop through the array and pass the id to get the specific user data and photo if it has one
for (var i = 0; i < ids.length; i++) {
callRestMessage(ids[i]);
}
} catch (err) {
gs.info('CDL: REST Users Uncaught error: ' + err);
}
function callRestMessage(ids) {
try {
//Call individual REST message to get specific user photo info
var rPhoto = new sn_ws.RESTMessageV2('HRPeopleSoft Photo', 'GET Photo');
rPhoto.setStringParameterNoEscape('EmployeeId', ids);
rPhoto.setStringParameterNoEscape('LastModifiedDatetime', lastEdited);
rPhoto.setEccParameter('skip_sensor', true);
var photoResponse = rPhoto.execute();
photoResponse.waitForResponse(360);
var photoResponseBody = photoResponse.getBody();
var photoHttpStatus = photoResponse.getStatusCode();
//Convert JSON formatted string to a JavaScript Object
var parser2 = new JSONParser();
var responseObj2 = parser2.parse(photoResponseBody);
var peopleSoftRecord = {
'EmployeeId': responseObj2.Response.Data.Employee.EmployeeId,
'ShowPhoto': responseObj2.Response.Data.Employee.ShowPhoto,
'HasPhoto': responseObj2.Response.Data.Employee.HasPhoto,
'Photo': responseObj2.Response.Data.Employee.Photo,
'ModifiedDatePhoto': responseObj2.Response.Data.Employee.ModifiedDatePhoto,
'ModifiedDate': responseObj2.Response.Data.Employee.ModifiedDate,
'lastEdited': lastEdited
};
import_set_table.insert(peopleSoftRecord);
} catch (err) {
gs.info('CDL: REST Photo Uncaught error: ' + err);
}
}
})(import_set_table, data_source, import_log, last_success_import_time);
And it works great, creating and populating the import set. I then want it to call a subflow that will process the data, updating our user photos after converting them from base64. I've validated that the subflow works correctly when tested, so the last piece is getting the import set to trigger the subflow
I used this post as a roadmap but can't seem to get the subflow to fire. the transform map doesn't need to do anything except fire off the subflow, so I just have the following onAfter transform script in it:
(function() {
try {
var inputs = {};
inputs['importRow'] = source; // Object
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.peoplesoft_photo_process').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Current subflow has no outputs defined.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
When I have it execute the transform, the subflow doesn't get triggered. I'm sure I'm missing something easy, can anyone help me out?
BTW, this is how the inputs on the subflow are set up:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2022 01:24 AM
Some quick things I'd try:
1. Have you logged inside the try block to check that it's actually attempting the call?
2. If it's not logging this out do you need to run the code snippet inside the runTransformScript function like:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// insert the Sub flow code snippet here
})(source, map, log, target);
3. Is the Sub flow active and published?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2022 06:48 AM
Good questions Geoff, here's what I have so far:
Current version of the onAfter Script, properly copied this time:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
gs.info("CDL: 1. onAfter Script started")
try {
gs.info("CDL: 3. inside try")
var inputs = {};
inputs['importRow'] = source; // Object
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow('global.peoplesoft_photo_process').inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.peoplesoft_photo_process').inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Current subflow has no outputs defined.
} catch (ex) {
var message = ex.getMessage();
gs.error("CDL: onAfter Error: " + message);
}
})(source, map, log, target);
As you can see, I added some logging. Here's what I get for each row when I run the transform:
CDL: 1. onAfter Script started
CDL: 3. inside try
CDL: onAfter Error: Invalid ComplexObject input format found
And yes, the subflow is active and published
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2022 07:29 AM
Looks like the format of the data you are passing doesn't match what you have defined for your Sub flow input based on that error message in the catch block.
Can you log out what 'source' looks like in the onAfter Script:
gs.log(typeof object); // should return "object"
gs.log(JSON.stringify(object)); // should return the object data
At least then you can confirm the 'source' object matches what you have defined in the Sub flow input in terms of structure and key values.