Answered by:
If a Foreach Loop Container finds no files in the directory...

Question
-
...is there a predefined variable I can use in the next precedence constraint to stop the package from continuing on to the next task?
Forgive me, I am sure this is a painfully obvious answer to someone, just not to me.
Thank you very much.Tuesday, September 22, 2009 7:40 PM
Answers
-
If you are setting a variable in the Foreach Loop and the foreach loop doesn't find anything to process, you can test for the absence of data in that variable in the precedence constraint between the foreach loop and the next task on the control flow.So, if you setup a variable, @FileName and you set its default value = "", and you have the foreach loop set to populate @FileName with the file name for each iteration of the foreach loop, if the foreach loop doesn't iterate over anything, the variable @FileName will remain set to "". So in the precedence constraint, you can test for @FileName != "" in order to continue on to the next task.
Phil Brammer | http://www.ssistalk.com- Proposed as answer by Nik - Shahriar Nikkhah Tuesday, September 22, 2009 7:57 PM
- Marked as answer by ckbkyne Tuesday, September 22, 2009 8:00 PM
Tuesday, September 22, 2009 7:46 PM
All replies
-
If you are setting a variable in the Foreach Loop and the foreach loop doesn't find anything to process, you can test for the absence of data in that variable in the precedence constraint between the foreach loop and the next task on the control flow.So, if you setup a variable, @FileName and you set its default value = "", and you have the foreach loop set to populate @FileName with the file name for each iteration of the foreach loop, if the foreach loop doesn't iterate over anything, the variable @FileName will remain set to "". So in the precedence constraint, you can test for @FileName != "" in order to continue on to the next task.
Phil Brammer | http://www.ssistalk.com- Proposed as answer by Nik - Shahriar Nikkhah Tuesday, September 22, 2009 7:57 PM
- Marked as answer by ckbkyne Tuesday, September 22, 2009 8:00 PM
Tuesday, September 22, 2009 7:46 PM -
Inside foreach loop your must be using a string variable to store the filename.
Let the initial value of the variable is abc (while defining the variable).
Then you can add this variable in precedence constraint. If the value is abc, it means no file is found in the directory and you can stop the package from continuing onto next task.
I am not aware of any predefined variable. Lets wait for experts to share there views
Nitesh Rai- Please mark the post as answered if it answers your questionTuesday, September 22, 2009 7:52 PM -
Hi,
if for each loop container doesn't find any file in specifird directory then the tasks available inside the loop will not execute.
so there is no need to use any variable for this.
for checking this, you can follow these steps:
step1; take for each loop container
Step2: drag script task inside this
Step3; write a code inside the script task
Msgbox("1")
Step4: Check the result.
Thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your questionTuesday, September 22, 2009 8:07 PM -
If you are setting a variable in the Foreach Loop and the foreach loop doesn't find anything to process, you can test for the absence of data in that variable in the precedence constraint between the foreach loop and the next task on the control flow.
So, if you setup a variable, @FileName and you set its default value = "", and you have the foreach loop set to populate @FileName with the file name for each iteration of the foreach loop, if the foreach loop doesn't iterate over anything, the variable @FileName will remain set to "". So in the precedence constraint, you can test for @FileName != "" in order to continue on to the next task.
Phil Brammer | http://www.ssistalk.com
i am disagree with this. this is not an answer. you can't access these variables inside the for each loop.
Phil, please check at your end.
Thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your questionTuesday, September 22, 2009 8:09 PM -
If you are setting a variable in the Foreach Loop and the foreach loop doesn't find anything to process, you can test for the absence of data in that variable in the precedence constraint between the foreach loop and the next task on the control flow.
So, if you setup a variable, @FileName and you set its default value = "", and you have the foreach loop set to populate @FileName with the file name for each iteration of the foreach loop, if the foreach loop doesn't iterate over anything, the variable @FileName will remain set to "". So in the precedence constraint, you can test for @FileName != "" in order to continue on to the next task.
Phil Brammer | http://www.ssistalk.com
i am disagree with this. this is not an answer. you can't access these variables inside the for each loop.
Phil, please check at your end.
Thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your question
Phil Brammer | http://www.ssistalk.comTuesday, September 22, 2009 8:12 PM -
Hi Phil,
you can't access those variables inside the foreach loop container. can you please give me the example for that (step-by-step). i would like to check that.
can you please try my above answer at your end?
:)
thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your questionTuesday, September 22, 2009 8:17 PM -
Hi Phil,
Yes, you can. Simply use the Variable Mappings section of the Foreach Loop wizard.
you can't access those variables inside the foreach loop container. can you please give me the example for that (step-by-step). i would like to check that.
can you please try my above answer at your end?
:)
thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your question
Phil Brammer | http://www.ssistalk.comTuesday, September 22, 2009 8:29 PM -
Hi,
The problem with this solution is that the user does not want the task AFTER the foreach loop (not inside the foreach loop) to execute if the foreach loop doesn't find anything to loop over.
if for each loop container doesn't find any file in specifird directory then the tasks available inside the loop will not execute.
so there is no need to use any variable for this.
for checking this, you can follow these steps:
step1; take for each loop container
Step2: drag script task inside this
Step3; write a code inside the script task
Msgbox("1")
Step4: Check the result.
Thanks-
Let us TRY this | Don’t forget to mark the post(s) that answered your question
Phil Brammer | http://www.ssistalk.comTuesday, September 22, 2009 8:31 PM -
The problem with this solution is that the user does not want the task AFTER the foreach loop (not inside the foreach loop) to execute if the foreach loop doesn't find anything to loop over.
Phil Brammer | http://www.ssistalk.com
Ok, got it. I was taking it otherwise (inside the loop).
Thanks for clearing the problem.
:)
Let us TRY this | Don’t forget to mark the post(s) that answered your questionTuesday, September 22, 2009 8:36 PM