Skip to content
+1-888-319-3663

COMMUNITY FORUM

Deleting records before the map runs

Pieter du Toit asked 1 year ago
I have a catch-22 situation that I hope someone can give me a work around for.  The map I created uses an Excel file that I put in the watched folder which then uploads the records into a SQL table.  No problems there.  I also added a task that runs before the map that deletes all the records that are in the table.  So basically, what I want is for the table to be cleared, the new records to be uploaded and for it to remain in the table until the map runs again.  This works fine when I run the map manually but here is the problem.  When I put it on a schedule, it seems that the before map task actually runs every time the scheduled time comes around even if there is no Excel file in the watched folder.  This then wipes out the records in the table which creates a problem since I need the records to stay there until the next time I actually put a new spreadsheet in the watched folder.  If there is no file in the watched folder, the map should just stop there, it should not run any of the task, then stop.
 
Thanks
Answers
Patrick Roth Staff answered 1 year ago
If there is no file in the watched folder, the map should just stop there, it should not run any of the task, then stop.”
The pre-map tasks run before the map actually runs.  So at that point we don’t know if there is data or not.
But if you wanted, just write some .NET code that runs before your SQL tasks that looks in the source folder if there are files or not.
check for source files to process on map pre
if no files, return false and set Cancel Processing for fail
map stops right there silently.
dim SourcePath as string  = “C:\eOne\FixedWidthFolderDS\source\”
‘get excel files from source folder
Dim filePaths As String() = Directory.GetFiles(SourcePath, “*.xlsx”)
if filePaths.Length > 0 then
  return true
else
  return false
end if
So here, if the code finds files, it returns “true” and the map processes normally.
If no files, it returns false and map execution stops.
 
Pieter du Toit answered 1 year ago
Thanks, that seems to have done the trick.

If you would like to submit an answer or comment, please sign in to the eOne portal.