<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Trigger subflow from Data Source/Transform Map in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388405#M932820</link>
    <description>&lt;P&gt;I have created a Custom (Load by Script) data source with the following script:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(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 &amp;lt; 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);&lt;/LI-CODE&gt;&lt;P&gt;And it works great, creating and populating the import set.&amp;nbsp; 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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used &lt;A href="https://www.servicenow.com/community/developer-forum/can-flow-designer-be-triggered-by-import-table-records/m-p/1355303" target="_self"&gt;this post&lt;/A&gt; as a roadmap but can't seem to get the subflow to fire.&amp;nbsp; the transform map doesn't need to do anything except fire off the subflow, so I just have the following&amp;nbsp; onAfter transform script in it:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(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);
	}
	
})();&lt;/LI-CODE&gt;&lt;P&gt;When I have it execute the transform, the subflow doesn't get triggered.&amp;nbsp; I'm sure I'm missing something easy, can anyone help me out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, this is how the inputs on the subflow are set up:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="conanlloyd_0-1668832867303.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/218666i22ACD6AE9F8AB964/image-size/medium?v=v2&amp;amp;px=400" role="button" title="conanlloyd_0-1668832867303.png" alt="conanlloyd_0-1668832867303.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Nov 2022 04:43:07 GMT</pubDate>
    <dc:creator>conanlloyd</dc:creator>
    <dc:date>2022-11-19T04:43:07Z</dc:date>
    <item>
      <title>Trigger subflow from Data Source/Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388405#M932820</link>
      <description>&lt;P&gt;I have created a Custom (Load by Script) data source with the following script:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(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 &amp;lt; 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);&lt;/LI-CODE&gt;&lt;P&gt;And it works great, creating and populating the import set.&amp;nbsp; 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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used &lt;A href="https://www.servicenow.com/community/developer-forum/can-flow-designer-be-triggered-by-import-table-records/m-p/1355303" target="_self"&gt;this post&lt;/A&gt; as a roadmap but can't seem to get the subflow to fire.&amp;nbsp; the transform map doesn't need to do anything except fire off the subflow, so I just have the following&amp;nbsp; onAfter transform script in it:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(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);
	}
	
})();&lt;/LI-CODE&gt;&lt;P&gt;When I have it execute the transform, the subflow doesn't get triggered.&amp;nbsp; I'm sure I'm missing something easy, can anyone help me out?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BTW, this is how the inputs on the subflow are set up:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="conanlloyd_0-1668832867303.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/218666i22ACD6AE9F8AB964/image-size/medium?v=v2&amp;amp;px=400" role="button" title="conanlloyd_0-1668832867303.png" alt="conanlloyd_0-1668832867303.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 04:43:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388405#M932820</guid>
      <dc:creator>conanlloyd</dc:creator>
      <dc:date>2022-11-19T04:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger subflow from Data Source/Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388441#M932833</link>
      <description>&lt;P&gt;Some quick things I'd try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Have you logged inside the try block to check that it's actually attempting the call?&lt;/P&gt;&lt;P&gt;2. If it's not logging this out do you need to run the code snippet inside the&amp;nbsp;runTransformScript function like:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	// insert the Sub flow code snippet here
})(source, map, log, target);&lt;/LI-CODE&gt;&lt;P&gt;3. Is the Sub flow active and published?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 09:24:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388441#M932833</guid>
      <dc:creator>Geoff_T</dc:creator>
      <dc:date>2022-11-19T09:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger subflow from Data Source/Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388501#M932855</link>
      <description>&lt;P&gt;Good questions Geoff, here's what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current version of the onAfter Script, properly copied this time:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(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);&lt;/LI-CODE&gt;&lt;P&gt;As you can see, I added some logging.&amp;nbsp; Here's what I get for each row when I run the transform:&lt;BR /&gt;CDL: 1. onAfter Script started&lt;BR /&gt;CDL: 3. inside try&lt;BR /&gt;CDL: onAfter Error: Invalid ComplexObject input format found&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;And yes, the subflow is active and published&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 14:48:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388501#M932855</guid>
      <dc:creator>conanlloyd</dc:creator>
      <dc:date>2022-11-19T14:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trigger subflow from Data Source/Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388506#M932857</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you log out what 'source' looks like in the&amp;nbsp;&lt;SPAN&gt;onAfter Script&lt;/SPAN&gt;:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;gs.log(typeof object); // should return "object"
gs.log(JSON.stringify(object)); // should return the object data&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 15:29:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/trigger-subflow-from-data-source-transform-map/m-p/2388506#M932857</guid>
      <dc:creator>Geoff_T</dc:creator>
      <dc:date>2022-11-19T15:29:42Z</dc:date>
    </item>
  </channel>
</rss>

