The Issue with the Email Task
In SmartConnect.com, I run a scheduled integration that frequently returns no data from the source.
I created an Integration Post Success Email Task that uses the built-in global variables for GlobalProcessCount and GlobalSuccessCount to show the number of source records, as well as how many records were successfully integrated in the email body.

This works nicely when there is data to process, however when there is not, I get an email telling me that the integration was a success per the screenshot below.

We notice that the GlobalProcessCount is blank and not zero as expected. The GlobalSuccessCount is also zero since there was no data to process.

Because there was no data to process, this email is unnecessary, and I’d rather not receive it. Is there a way to stop the Email Task from running?
How to Cancel an Email Task
Yes, we can stop any kind of task in two ways in SmartConnect, depending on our needs and version of SmartConnect.
In SmartConnect.com, the easiest solution is to set this on the Map | Options tab.

On the “If No Data Returned from Data Source” line, the second option is to define what happens if there is no data. There are defined tasks, which could be any type of Task — Script, SQL, or Email Task in this case.
The default is “Run defined tasks,” which is why, when the map is successful, it sends the email. You can try setting this to “Don’t run any tasks”.
If you are using SmartConnect 21 on-prem, this isn’t currently an option. However, you can use a Script task to do the same thing by examining the same system variables.
Because there is no data, the GlobalProcessCount would be 0 or an empty value. The same applies to GlobalSuccessCount and GlobalErrorCount. You could check any of these variables to determine if there were successful or unsuccessful records processed, depending on your exact needs.
Make sure that the new Script task runs before the tasks you need to be cancelled. New tasks get created after the existing tasks, so you would have to manually change the order.

Also, on the script task created, make sure to switch the “On Failure event to “Cancel processing”.

if (!isNaN(this.ProcessSuccessCount)|| Number(this.ProcessSuccessCount) == 0)
{
return false;
}
return true;
int count = 0;
if (!int.TryParse(GlobalProcessCount, out count) || count == 0)
{
return false;
}
return true;
Dim count As Integer = 0
If Not Integer.TryParse(GlobalProcessCount, count) OrElse count = 0 Then
Return False
End If
Return True
After adding in the Script task, the email task gets cancelled without error and the message is no longer sent.
If you have any questions or run into any issues while trying to cancel an email task in SmartConnect, please reach out to support@eonesolutions.com for assistance.