In my SmartConnect integration, I need to add a small delay between the map tasks. What is the best way to do this in SmartConnect.com and SmartConnect on-premises?
There isn’t a built-in method in SmartConnect that has this feature, however we can write a scripting task to add this into our integration to introduce the necessary delay.
SmartConnect.com uses JavaScript and SmartConnect 2018/21 for on-premises uses .NET scripting and the approach is different between them.
The JavaScript implementation in SmartConnect.com does not have a function to “sleep” or “delay”. We have to build one the only way we can. In this case, we can get the current datetime and then run in a loop to keep checking the current time to see if our interval has elapsed. After the specified interval elapses, we break out of the loop and the task returns and the integration continues normally.
function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds){ break; } } } sleep(500); return true;
We could use the same brute-force approach as SmartConnect.com but that isn’t necessary because the on-premises version uses .NET and there is a .NET method to do this for us.
The advantage here is that the this essentially does put the “current SmartConnect thread to sleep” vs force it to loop as we do in Javascript.
'sleep for 500 milliseconeds/.5 seconds System.Threading.Thread.Sleep(500) return true
This screenshot is from SmartConnect 2018 but the SmartConnect 21 window is similar.
We could use the same brute-force approach as SmartConnect.com but that isn’t necessary because the on-premises version uses .NET and there is a .NET method to do this for us.
The advantage here is that the this essentially does put the “current SmartConnect thread to sleep” vs force it to loop as we do in Javascript.
//sleep for 500 milliseconds/.5 seconds System.Threading.Thread.Sleep(500); return true;
This screenshot is from SmartConnect 21 but SmartConnect 2018 is similar.