UI:include (facelet) within foreach loop
Hi I'm trying to do a ui:include of another page within a foreach loop, the path of the page to include comes out of the variable of the foreach loop, but this seems not to be working, is there a workaround?
<c:foreach value="#{myBean.services}" var="service">
<h:column>
<ui:include src="/myservices/#{service.name}/serviceMenu.xhtml"/>
</h:column>
</c:foreach>
thx
THX for the reply
I tried with the h:dataTable and I have the same problem, dynamic includes do not work within the dataTable loop, the output is ok I tried
<h:dataTable>
<h:column>
<h:panelGroup rendered="#{service.normalizedName eq 'Test'}">
<ui:include src="/secure/myservices/Test/serviceMenu.xhtml"/>
</h:panelGroup>
</h:column>
</h:dataTable>
then it is working but I have to create ab EL expression for each possible service which is not maintainable
any ideas?
Similar Messages
-
Introduction
We need to loop through all the flat files that have the same structure in a folder and import all the data to a single SQL Server table. How can we obtain the total count of the rows inserted to the destination SQL Server table?
Solution
We can use Execute SQL Task or Script Task to aggregate the row count increment for each iteration of the Foreach Loop Container. The following steps are the preparations before we add the Execute SQL Task or Script Task:
Create a String type variable FilePath, two Int32 type variables InsertRowCnt and TotalRowCnt.
Drag a Foreach Loop Container to the Control Flow design surface, set the Enumerator to “Foreach File Enumerator”, specify the source folder and the files extension, and set the “Retrieve file name” option to “Fully qualified”.
On the “Variable Mappings” tab of the container, map the variable FilePath to the collection value.
Drag a Data Flow Task to the container, in the Data Flow Task, add a Flat File Source, a Row Count Transformation, and an OLE DB Destination, and join them. Create a Flat File Connection Manager to connect to one of the flat files, and then configure the
Flat File Source as well as the OLE DB Destination adapter. Set the variable for the Row Count Transformation to “User::InsertRowCnt”.
Open the Property Expressions Editor for the Flat File Connection Manager, and set the expression of “ConnectionString” property to
“@[User::FilePath]”.
(I) Execute SQL Task Method:
In the Control Flow, drag an Execute SQL Task under the Data Flow Task and join them.
Create one or using any one existing OLE DB Connection Manager for the Execute SQL Task, set the “ResultSet” option to “Single row”, and then set the “SQLStatement” property to:
DECLARE @InsertRowCnt INT,
@TotalRowCnt INT
SET @InsertRowCnt=?
SET @TotalRowCnt=?
SET @TotalRowCnt=@InsertRowCnt+@TotalRowCnt
SELECT TotalRowCnt=@TotalRowCnt
On to parameter 1.
On the “Result Set” tab of the Execute SQL Task, map result 0 to variable “User::TotalRowCnt”.
(II) Script Task Method:
In the Control Flow, drag a Script Task under the Data Flow Task and join them.
In the Script Task, select variable InsertRowCnt for “ReadOnlyVariables” option, and select variable TotalRowCnt for “ReadWriteVariables”.
Edit the Main method as follows (C#):
public void Main()
// TODO: Add your code here
int InsertRowCnt = Convert.ToInt32(Dts.Variables["User::InsertRowCnt"].Value.ToString()
int TotalRowCnt = Convert.ToInt32(Dts.Variables["User::TotalRowCnt"].Value.ToString());
TotalRowCnt = TotalRowCnt + InsertRowCnt;
Dts.Variables["User::InsertRowCnt"].Value = TotalRowCnt;
Dts.TaskResult = (int)ScriptResults.Success;
Or (VB)
Public Sub Main()
' Add your code here
Dim InsertRowCnt As Integer =
Convert.ToInt32(Dts.Variables("User::InsertRowCnt").Value.ToString())
Dim TotalRowCnt As Integer =
Convert.ToInt32(Dts.Variables("User::TotalRowCnt").Value.ToString())
TotalRowCnt = TotalRowCnt + InsertRowCnt
Dts.Variables("User::TotalRowCnt").Value = TotalRowCnt
Dts.TaskResult = ScriptResults.Success
End Sub
Applies to
Microsoft SQL Server 2005
Microsoft SQL Server 2008
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2012
Microsoft SQL Server 2014
Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.Hi ITBobbyP,
If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
If in this scenario, please refer to the following tips:
The Foreach Loop container should be configured as shown below:
Enumerator: Foreach ADO.NET Schema Rowset Enumerator
Connection String: The OLE DB Connection String for the excel file.
Schema: Tables.
In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
The connection string for Excel Connection Manager is the original one, we needn’t make any change.
Change Table Name or View name to the variable Sheet_Name.
If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
ForEach Loop - Parsing XML subgroup into Variables
Hi all,I am designing a new ETL process using SSAS.
We have a controller package which receives an XML string at run time into a variable called BatchRequest :-
<Batch>
<Request>
<Name>Filemon</Name>
<Params>
<filepaths>
<Sourcepath>d:\temp</Sourcepath>
<Destpath>D:\temp2</Destpath>
<Archivename>\Archive</Archivename>
</filepaths>
</Params>
</Request>
</Batch>
The Batch can contain a number of Requests and a ForEach Loop is used to parse the text for the Name node and the text for the Params Node into variables RequestName and RequestParams respectively.
however, what I want to be able to do is to take the text for <name> into Requestname but take the entire XML sub string for <Params> into RequestParams.
At the moment I get the text only (e.g. d:\tempd:\temp2\Archive).
The Requestname is used by an XML task within the ForEach loop to retrieve full package path details from an external config file, and hence it only needs to be a keyword.
I played with the idea of including <Params> as a subnode for <Name>, only populating RequestName in the loop parser and then having an XML task which would parse the related parameter string, but i don't know how to tell the XML task that I
want the parameter string where the <Name> is Filemon (in this example).
Can anyone give me some suggestions or pointers?
Thanks
Iain
IainHi idcowden,
Glad to hear that you have resolved the issue on your own. Thank you for sharing the solution.
Regards,
Mike Yin
TechNet Community Support -
Foreach Loop only looping once
Hi,
Please be patient and bear with me, for I am new to SSIS packages.
I am using SQL Server 2008 R2 to host the SQL Agent job and the SSIS package.
I am using Visual Studio 2008 Professional Edition for designing the SSIS package. It is version 9.0.30729, Version 3.5 SP1.
I am on a Windows 8 machine.
My Foreach Loop Container seems to iterate only once when it should iterate numerous times, and this issue happens BOTH when I execute the SSIS package from within Visual Studio AND when I run a SQL Agent job to execute the SSIS package.
For the solution within Visual Studio, I have False for the property Run64BitRuntime.
In the SSIS pckg in Visual Studio, I have in the Variables pane a number of variables and these following variables pertain to my problem:
Name: objRs Scope: the name of the SSIS package DataType: Object Value: System.Object
Name: txtVendorFamilyNumber Scope: the name of the SSIS package DataType: String Value: 111111
The value "111111" that I entered into the txtVendorFamilyNumber variable in the Variable Pane is NOT a realistic value as there are no vendor family numbers that have the value 111111. I will populate dynamically the real vendor family numbers
from within the SSIS package.
When I imported the SSIS package to SQL Server 2008 R2, via the ellipsis button for the Protection Level I chose the "Rely on server storage and roles for access control" choice.
Concerning the flow of the SSIS package, going down within Visual Studio from the beginning of the flow of the SSIS package, eventually I have an Execute SQL Task. In its General tab, it has "1252" for CodePage property, "Full result set"
for ResultSet property, "OLE DB" for ConnectionType property, "Direct input" for SQL Source Type property, "False" for BypassPrepare property, and the following for the SQLStatement property:
select txtVendorFamilyNumber from tmpVendorFamily where VendorID = (select min(VendorID) from tmpVendorFamily)
In the tmpVendorFamily table on SQL Server 2008 R2, there are 379 rows of results for the SELECT statement above (starting with the values 100110, 100115, 100120, 100130, through the LAST row's value 106370.
In the Parameter Mapping tab of the Execute SQL Task Editor, I have nothing. In the Expressions tab of the Execute SQL Task Editor, I have nothing.
In the Result Set tab of the Execute SQL Task Editor, I have the value 0 for Result Name property and I have the value User::objRs as the value in the Variable Name property.
This Execute SQL Task has a green arrow (Constraint evaluation operation, Success in Value drop down) to the Foreach Loop Container.
In the Foreach Loop Editor, in the Collection tab, I have "Foreach ADO Enumerator" as the value in the Enumerator property. In the drop down for ADO Object Source Variable, I have chosen the User::objRs, and I have the radio button "Rows in
the first table" selected.
In the Foreach Loop Editor, in the Expressions tab, I have nothing.
In the Foreach Loop Editor, in the Variable Mappings tab, I have "User::txtVendorFamilyNumber" for the Variable property and I have the value "0" for the Index property.
So in the Foreach Loop, I first have a Script Task with the ReadOnly variable User::txtVendorFamilyNumber and with the ReadWrite variable User::TESTING_OnlyTesting that I created with a package scope, string datatype, and no default value. This Script Task
has the following code for testing purposes:
Dim strFullVerbiage As String
strFullVerbiage = "The value is: "
Dts.Variables("User::TESTING_OnlyTesting").Value = strFullVerbiage + Dts.Variables("User::txtVendorFamilyNumber").Value.ToString()
Dts.TaskResult = ScriptResults.Success
I have next in the Foreach Loop Container a Send Mail task. In the Expressions tab of the Send Mail Task Editor, I have for the Message Source property the following:
@[User::TESTING_OnlyTesting]
The remaining tasks (including FTP Tasks) in the Foreach Loop Container are disabled for now as I am trying to figure out why the Foreach Loop only iterates the FIRST time, only iterates once.
When I run on SQL Server 2008 R2 the SELECT statement from the Execute SQL Task, I get 379 rows of results. The default value 111111 that I entered into the Variable Pane for the txtVendorFamilyNumber variable does NOT exist in any of these 379 rows of results.
The 1st row of results has for the txtVendorFamilyNumber column the value 100110. Then the subsequent rows of results have the values 100115, 100120, 100130, et cetera, ending with the value 106370 in the last row of results.
I imported the SSIS package into Integration Services on SQL Server 2008 R2. When I imported to Integration Services, in the Import Package editor for the Protection Level I chose the "Rely on server storage and roles for access control" choice
because there are FTP Tasks and we needed to use this "Rely on server storage and roles for access control" choice.
I created a SQL Agent job that executes this SSIS package.
When I run the SQL Agent job, no error happens and I get only ONE email with the value 100110 for the vendor family number in it. I should get 379 emails total, the 2nd email showing 100115, the 3rd email showing 100120, et cetera.
When I was testing while executing the SSIS package from within Visual Studio, I did NOT have the Send Mail task and I only had enabled one Script Task that had the ReadOnly variable User::txtVendorFamilyNumber and the following lines of code:
MsgBox(CType(Dts.Variables("User::txtVendorFamilyNumber").Value, String))
Dts.TaskResult = ScriptResults.Success
Executing the SSIS package with only this Script Task enabled within the Foreach Loop Container, I would get the ONE message box showing 100110 but I would not get any message box for a SECOND ITERATION of the loop.
Since my txtVendorFamilyNumber in the Variables Pane has the default hard-coded value 111111 that does NOT exist in the result set of the Execute SQL Task that feeds the Foreach Loop, and since the first and only email sent shows the value 100110 when I
run the SQL Agent job that runs the SSIS package that is set up to send an email from within the Foreach Loop Container, the FIRST LOOP seems to run correctly and shows correctly the 1st value 100110 in the 379 rows of results that populate the Foreach Loop
Container. Why does the Foreach Loop Container NOT loop more than once?
Could anybody give me any suggestions as to what the problem might be?
I thank you in advance for your consideration of my problem. I have been reading and reading on the Internet to try to find a solution but I have not solved yet my problem with the Foreach loop only iterating once.
Thanks much to you.Gregarious greetings Arthur,
I very much appreciate your reply.
This morning I figured out my problem with the help of a fellow employee.
In my original post higher up, I had typed about the SELECT statement in the Execute SQL Task that is just before the Foreach Loop Container and that populates the User::objRs, and this SELECT statement was in the old DTS package in an old ActiveX script
task. The SELECT statement was in an old DTS package in an old ActiveX script task and I am creating a new SSIS package to replace the old DTS package so that we can move from the old version of SQL Server to a new SQL Server 2008 R2 server. Here is that
SELECT statement:
select txtVendorFamilyNumber from tmpVendorFamily where VendorID = (select min(VendorID) from tmpVendorFamily)
That SELECT statement above returns ONLY ONE result. I had not noticed it. That SELECT statement fills the objRs result set. The green arrow goes from the Execute SQL Task that has the SELECT statement down to the Foreach Loop Container that loops over the
result set. Since the SELECT statement that fills the result set only has one row of results, the Foreach Loop only looped once.
So for the Execute SQL Task that populates the result set User::objRs, I changed the SELECT statement to be the following:
--In the Utilities DB, this tmpVendorFamily table
--has only two columns named VendorID and txtVendorFamilyNumber.
SELECT DISTINCT txtVendorFamilyNumber
FROM Utilities.dbo.tmpVendorFamily
ORDER BY txtVendorFamilyNumber
Now the Foreach Loop will loop 379 times since the SELECT statement immediately above yields 379 rows of results.
So the Foreach Loop Container was fine. Its Collection tab has the "Foreach ADO Enumerator" for the Enumerator and has the "User::objRs" for the ADO Object Source Variable. Its Variable Mappings tab has "User::txtVendorFamilyNumber"
for the Variable and has "0" for the Index.
My problem was the SELECT statement in the Execute SQL Task that immediately precedes the Foreach Loop Container and that fills the User::objRs result set. The SELECT statement yielded only ONE row of results. When I corrected this morning that SELECT statement
so that it correctly yields 379 rows of results, the Foreach Loop Container loops 379 rows.
Thanks again for replying and trying to help. I very much appreciate it.
I consider this thread that I created to be closed since I figured out this morning how I needed to correct the SELECT statement in the Execute SQL Task that fills the result set on which the Foreach Loop loops.
Misko_Hviezdoslav 27-JAN-2015 -
I know I've REALLY struggled with this before. I just don't understand why this has to be soooooo difficult.
I can very easily do a straight Data Pump of a .xlsX File into a SQL Server Table using a normal Excel Connection and a normal Excel Source...simply converting Unicode to DT_STR and then using an OLE DB Destination of the SQL Server Table.
If I want to make the SSIS Package a little more flexible by allowing multiple .xlsX spreadsheets to be pumped in by using a Foreach Loop Container, the whole SSIS Package seems to go to hell in a hand basket. I simply do the following...
Put the Data Flow Task within the Foreach Loop Container
Add the Variable Mapping Variable User::FilePath that I defined as a Variable and a string within the FOreach Loop Container
I change the Excel Connection and its Expression to be ExcelFilePath ==> @[User::FilePath]
I then try and change the Excel Source and its Data Access Mode to Table Name or view name variable and provide the Variable Name User::FilePath
And that's when I run into trouble...
Exception from HRESULT: 0xC02020E8
Error at Data Flow Task [Excel Source [56]]:SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occured. Error code: 0x80004005.
Error at Data Flow Task [Excel Source [56]]: Opening a rowset for "...(the EXACT Path and .xlsx File Name)...". Check that the object exists in the database. (And I know it's there!!!)
I don't understand by adding a Foreach Loop Container to try and make this as efficient as possible has caused such an error unless I'm overlooking something. I have even tried delaying my validations and that doesn't seem to help.
I have looked hard in Google and even YouTube to try and find a solution for this but for the life of me I cannot seem to find anything on pumping a .xlsX file into SQL Server using a Foreach Loop Container.
Can ANYONE please help me out here? I'm at the end of my rope trying to get this to work. I think the last time I was in this quandry, trying to pump a .xlsX File into a SQL Server Table using a Foreach Loop Container in SSIS, I actually wrote a C# Script
to write the contents of the .xlsX File into a .csv File and then Actually used the .csv File to pump the data into a SQL Server Table.
Thanks for your review and am hoping and praying for a reply and solution.Hi ITBobbyP,
If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
If in this scenario, please refer to the following tips:
The Foreach Loop container should be configured as shown below:
Enumerator: Foreach ADO.NET Schema Rowset Enumerator
Connection String: The OLE DB Connection String for the excel file.
Schema: Tables.
In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
The connection string for Excel Connection Manager is the original one, we needn’t make any change.
Change Table Name or View name to the variable Sheet_Name.
If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Hello everyone.
Faced very strange issue with account, which is used to run SSIS package.
The specific package uses Foreach Loop Container to retrieve file names within the specified folder, and put them into Import file task.
The package is set up to run under specific service account. This service account is given all permissions (Full control) to the folder where source files reside.
So the issue is: SSIS package fails to execute this task (Foreach Loop Container and then Import), and shows that no files are found in the directory (although files ARE there).
Once we're adding the service account into local Administrators group on the SQL Server, it works! Removing - does not work again. We cannot leave the service account as SQL server's admin as it's prohibited by our IT policies, and is just a bad practice.
Any ideas, please?
MCPHere's the real log output:
Date 16.04.2014 12:47:09
Log Job History (RU-BW: Update)
Step ID 1
Server Server
Job Name RU-BW: Update
Step Name bw_import_cust_master_data
Duration 00:00:02
Sql Severity 0
Sql Message ID 0
Operator Emailed
Operator Net sent
Operator Paged
Retries Attempted 0
Message
Executed as user: service_account Microsoft (R) SQL Server Execute Package Utility Version 10.50.4286.0 for 64-bit Copyright (C) Microsoft Corporation 2010. All rights reserved. Started: 12:47:09 Error: 2014-04-16 12:47:11.45
Code: 0xC0202070 Source: bw_import_cust_master_data Connection manager "Input" Description: The file name property is not valid. The file name is a device or contains invalid characters. End Error Error:
2014-04-16 12:47:11.47 Code: 0xC0202070 Source: bw_import_cust_master_data Connection manager "Input" Description: The file name property is not valid. The file name is a device or contains invalid characters. End
Error Error: 2014-04-16 12:47:11.48 Code: 0xC0202070 Source: bw_import_cust_master_data Connection manager "Input" Description: The file name property is not valid. The file name is a device or contains invalid
characters. End Error Error: 2014-04-16 12:47:11.48 Code: 0xC020207E Source: Import file Flat File Source [1] Description: The file name is not valid. The file name is a device or contains invalid characters.
End Error Error: 2014-04-16 12:47:11.48 Code: 0xC004701A Source: Import file SSIS.Pipeline Description: component "Flat File Source" (1) failed the pre-execute phase and returned error code 0xC020207E.
End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 12:47:09 Finished: 12:47:11 Elapsed: 2.324 seconds. The package execution failed. The step failed.
MCP -
Foreach Loop Container with a Data Flow Task looking for file from Connection Manager
So I have a Data Flow Task within a Foreach Loop Container. The Foreach Loop Container has a Variable Mapping of User:FileName to pass to the Data Flow Task.
The Data Flow Task has a Flat File Source since we're looking to process .csv Files. And the Flat File Source has a Flat File Connection Manager where I specified the File name when I created it. I thought you needed to do this even though it won't really
use it since it should be getting its File name from the Foreach Loop Container. But when attempting to execute, it is blowing up because it seems to be looking for my test file name that I indicated in the Flat File Connection Manager rather than the file
it should be trying to process in User:FileName from the Foreach Loop Container.
What am I doing wrong here??? I thought you needed to indicate a File name within the Flat File Connection Manager even though it really won't be using it.
Thanks for your review...I hope I've been clear...and am hopeful for a reply.
PSULionRPThe Flat File Connection manager's Connection String needs to be set to reference the variable used in the ForEach Loop:
Arthur My Blog -
MDS persistence for column within a loop
Hello,
I am trying out basic setup of MDS. I was able to make it work for most of my columns except for a column within a loop. I also tried using the ADF Read Only Dynamic table and it is not persisting any of the columns of the table, since it is inside the loop.
I would like to know if this is a bug when you apply MDS to component that has id that is dynamically incremented/generated.
mds customization file - c18 i s missing which should correspond to the dynamic column
<?xml version = '1.0' encoding = 'UTF-8'?>
<mds:customization version="11.1.1.60.13" xmlns:mds="http://xmlns.oracle.com/mds">
<mds:modify element="c17">
<mds:attribute name="displayIndex" value="1"/>
</mds:modify>
<mds:modify element="c21">
<mds:attribute name="displayIndex" value="2"/>
</mds:modify>
<mds:modify element="c16">
<mds:attribute name="displayIndex" value="3"/>
</mds:modify>
<mds:modify element="c20">
<mds:attribute name="displayIndex" value="4"/>
</mds:modify>
<mds:modify element="c19">
<mds:attribute name="displayIndex" value="5"/>
</mds:modify>
<mds:modify element="c28">
<mds:attribute name="displayIndex" value="6"/>
</mds:modify>
<mds:modify element="c27">
<mds:attribute name="displayIndex" value="11"/>
</mds:modify>
<mds:modify element="c22">
<mds:attribute name="displayIndex" value="12"/>
</mds:modify>
<mds:modify element="c15">
<mds:attribute name="displayIndex" value="0"/>
</mds:modify>
</mds:customization>
jspx related to the display, just to show the component id. In blue is the logic/code for dynamically displaying a column and the dropdown and contents of the dropdown
<af:forEach
items="#{pageFlowScope.SearchRules.filterBeans}" varStatus="index" var="def">
*<af:column id="c18" headerText="#{def.parameterDisplayName}">*
<af:selectOneChoice value="#{row.dataProvider.ruleColumns[index.index].attributeId}"
disabled="#{!(sessionScope.usersession.ruleAuth.isRoleForCreateEditRule and row.dataProvider.ruleColumns[index.index].isEdit)}"
clientComponent="true"
helpTopicId="#{row.dataProvider.ruleColumns[index.index].ruleTypeParameterID}"
autoSubmit="true" shortDesc="#{row.message}"
id="soc4445" valuePassThru="true"
valueChangeListener="#{pageFlowScope.SearchRules.ccsChange}">
<af:forEach items="#{bindings.Rule.rangeSet}" varStatus="att" >
<af:selectItem label="#{row.dataProvider.ruleColumns[index.index].attributes[att.index].assignedAttributeValue}"
value="#{row.dataProvider.ruleColumns[index.index].attributes[att.index].assignedAttributeID}"
rendered="#{row.dataProvider.ruleColumns[index.index].attributeSize > att.index}"
id="si4"/>
</af:forEach>
<!--f:selectItems value="#{row.dataProvider.ruleColumns[index.index].attributes}"
id="si4"/-->
</af:selectOneChoice>
</af:column>
</af:forEach>
Thanks,
CatherineHi,
the problem actually is that the id is the same for all of the occurences. So the forEach loop should create unique IDs for each occurence of a component.
Frank -
Yet another Try Catch question. Iterating through a ForEach loop
Confused on error handling in a Powershell ForEach loop. I’m looping through a list of registry keys, attempting
to open each one. If it succeeds, I do a bunch of stuff. If it fails, I want to skip to the next iteration.
If I was doing It in VBScript I’d do this:
For Each Thing In colThings
Open Thing
If Err.Number <> 0 Then
“oops”
Else
Do stuff
Do stuff
Do stuff
End If
Next
This is what I came up with in PowerShell. It seems to work, but just doesn’t seem powershell-ish. There must be a better way to use the catch output than just creating a $return variable and assigning it success or fail?
ForEach ($subKeyName in $subKeyNames)
try{$subKey = $baseKey.OpenSubKey("$subKeyName")}
catch{$return = "error" }
If($return -eq "error" )
“Oops”
Else
Do stuff
Do stuff
Do Stuff
I totally get what you're saying about formatting. I don't' have any habits yet, since I've only been working in Powershell since... well, what time is it now?
Unfortunately, It Has Been Decreed that we are no longer to use VBScript for any engineering solutions at work, so my 15 years experience in it now needs to be transitioned over asap. I don't have the luxury of crawling before I run. I'm trying not to be
frustrated, but it's like an English major waking up one day and being told "You must now speak French exclusively. Here's a book."
The Do Stuff example of my ForEach loop is about 50 lines of code involving matching values in subkeys of this registry key with another and collecting output. I tried wrapping the whole thing in a try section based on some examples, but it seemed odd, that's
why I'm asking. I'm used to tightly focused error handling at the point where an error may occur.
In this example I'm only interested in whether or not I can open the subkey (it exists, but I may not have permission). If I can't, there's no point in continuing with this iteration of the loop, I want to skip to the next one. So why include all the "Do
Stuff" in the the try section? From a readability viewpoint, it doesn't seem helpful.
Also, there may be more error handling deeper in the code. If I then put that in a try/catch, and then something else inside that, now I have nested try/catches mixed in with nested if/elses, all wrapped in a For loop.
Again, I can see how it works logically, but for readability not so much, and having all these braces 50 lines apart to match up is giving me eye strain :).
It sounds like David is agreeing with jrv, that putting the entire ForEach loop code into a try/catch is the conventional way to do it. I guess it makes as much sense as putting it all in an If-else-Endif, and I just need to adjust my paradigm.
But if not, my specific question was more along the lines of, is there a built in way to tell that the catch section has been executed, rather than me using it to populate an arbitrary variable and then read it? In VBScript, you execute something, and the
next line, you check the Err.number. I wasn't sure if you could do that with a try/catch. -
I have a JSTL forEach loop similar to below:
<c:forEach var="product" items="${sessionScope.products}">
<tr><td>${product.description}</td></tr>
</c:forEach>I would like to use a static class to format the description. Something like below, but I know I cannot do it this way. How can I accomplish this?
<tr><td>${ProductFormatter.getHtmlDescription(product)}</td></tr>thanksThe least change approach. If you have already have a static function to do this, then a function tag would be appropriate.
The function tag basically lets you call a static function from EL.
custom.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-
jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
>
<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://www.mytags.com/</uri>
<function>
<name>productFormatter</name>
<function-class>com.mypackage.ProductFormatter</function-class>
<function-signature>java.lang.String getHtmlDescription(com.mypackage.Product)</function-signature>
</function>
</taglib>If you include that tld in your WEB-INF directory, then the following in a JSP should work:
<%@ taglib uri="http://www.mytags.com/" prefix="my"%>
<c:forEach var="product" items="${sessionScope.products}">
<tr><td>${my:productFormatter(product)}</td></tr>
</c:forEach>Rather than putting the code in a static function, you might be better off encoding the logic into a custom tag. It depends on what your formatting function is like.
cheers,
evnafets -
I am trying to create a foreach loop that takes all txt files in Program Files and print only the names of files over 10KB.
This is what I got:
foreach($file in (Get-ChildItem -Path "c:\Program Files" -recurse -Include *.txt |
Select-Object FullName ))
if($file.size -gt 10KB)
Write-Host $file
I've been testing around with this for a bit now and doing some Googling to no avail, it'll work if I don't try to sort it by size and ask it just to print the name of all text files in Program Files. Any nudge in the right direction would be appreciated.Let me be more explicit. Whatou posted is not a loop.
Always start with HELP when you are learning. Ask your teacher to explain to you how to use HELP.
help foreach.
A ForEach loop cannot solve your issue here. You need to filter the results of a recursive search. In PowerShell this is almost never done with a loop. If your teacher tries to tell you otherwise you need to fire the teacher or take your money to a different
school.
Of course it may be more likly that you just didn't pay attention in class and are now asking us to do your homework for you.
Sorry. We don't do homework for children. This is a site for technicians who use scripting professionally. If you want to be a professional you need to do your homework No cheating. We are watching.
¯\_(ツ)_/¯ -
Characteristics Combinations at FOREACH loops
Hi experts,
I can not use some characteristics combinations at FOREACH loops.
Sample situation is below ;
Planning area is multiple planning area.However, at this situation i gather data from just one cube, not another cubes.
*There is data at below combination in the related cube.
0FISCPER3 (Posting Period)
0FISCYEAR (Posting year)
ZVKBUR (Organizational Unit)
ZVKGRP (Sales Office)
ZMATNR (material number)
ZSS(Sales responsible)
and some other fields.
At first planning level selected characteristics are ;
0FISCPER3 (Posting Period)
0FISCYEAR (Posting year)
ZVKBUR (Organizational Unit)
ZVKGRP (Sales Office)
ZMATNR (material number)
at selection tab, a variable is used for ZVKGRP.
when i use this combination at foreach loop i can see data at lt_cur001 internal table during debugging.
At second planning level selected characteristics are ;
0FISCPER3 (Posting Period)
0FISCYEAR (Posting year)
ZVKBUR (Organizational Unit)
ZVKGRP (Sales Office)
ZSS(Sales responsible)
at selection tab, a variable is used for ZSS.
when i use this combination at foreach loop i can see data at lt_cur001 internal table during debugging.
However, at third combination i can not see any data at ZMATNR field.
0FISCPER3 (Posting Period)
0FISCYEAR (Posting year)
ZVKBUR (Organizational Unit)
ZVKGRP (Sales Office)
ZSS(Sales responsible)
ZMATNR (Material Number)
at selection tab, a variable is used for ZSS.And i added '#' into this variable's values.
when i use this combination at a foreach i cannot see any data at lt_cur001-zmatnr field of internal table during debugging.
What do you recommend me to read data at above combination from this cube?
Best Regards,
KevserThere is transactional data like below combination in my cube :
0fiscyear = 2007
0fiscper3 = 001
zvkbur = 1031
zvkgrp = 101
zmatnr = 000000000000150008
zss = 31301003
and the value 31301003 for ZSS exists within the values of variable ZSS.
Kevser -
How can you see the progress when using a ForEach loop?
Hi,
I have an array with about 100 containers in it. My main thread uses a ForEach loop with an inner case structure with six possibilities. My previous program had all the steps in a very long list, executing them one by one. I find this new approach is much nicer to look at, and easier to change, but there isn't really any way of telling how far along the test is (unless you know it by heart). In the long list approach, you could see all the Done/Passed outcomes and how many remained, now there is no way of telling.
Any tips on making some kind of progress indication?
Solved!
Go to Solution.As ObjectReference parameter, you should use 'Nothing'. The last parameter (synchronuous?) you can choose true or false. Please refer to the documentation of PostUIMessageEx for further information.
The numeric parameter should range between 0-100. Since it is "Progress Percent", this makes sense, does it?
The status bar has several panes, one e.g. displaying the logged in user or the used process model. The pane on the right most side will display the Progress Percent if used in your sequence.
The default reporting, as already stated, includes this feature. So if you have a sequence with e.g. 500 steps, the reporting "will have a visible progress" in that pane (with less than 100 steps, it is most often too fast to see). Remember that NI Sequence Editor and the Full Featured User Interfaces do have this feature, the Simple UI does not have it.
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it. -
Use a external parameter in a foreach loop container
Hi
I use a parameter P1 in a package
This package contains also a foreach loop container including a parameter P2 (P1 is on outside of the foreach loop container)
In this foreach loop container, I need to insert into a table T1 the parameter P1 and P2 from an execute sql task :
INSERT INTO T1 (F1, F2) VALUES (?,?)
My question : how to access to the P1 parameter in the container ?
Thx for your helpI assume when you say parameter its in term of USER Variables defined in packages if yes then its essentially a scope thing, just define the scope of variable to outside and you should be able to access it.
If you mean P1 is something you assign from the Foreach look then assign then store this parameter as variable then assign the variable as you want to use it.
Abhinav http://bishtabhinav.wordpress.com/ -
Error 0x800A0BCD in a foreach loop container
Hi
I ve two nested foreach loop containers, all tasks included inside run well but when i launch the package i meet a error :
0x800A0BCD to the output of
the internal foreach loop container
How to see what happens wrong and how to solve this issue ?
ThxThis is an invalid set up.
It is hard to see the image.
Do not expect to have both successful completions to spawn two absolutely parallel processes.
To make it run in parallel just use two DFTs with each that are not connected together. Not connected is the catch, if max executables is not tweaked the package will spawn parallel exes to execute both DFTs more or less asynchronously.
Arthur My Blog
Maybe you are looking for
-
Hi I have a problem when trying to download music or videos purchased on Itunes on my mini Ipad. When reaching about ninty per cent of download it says error end try later. What can I do to solve this? App store and book store work fine and I have no
-
How can I use iPhone 3GS with an LCD Projector
Often I want to demonstrate a good app or iphone feature to a group of people. Hence I want to connect my iPhone to an LCD projector
-
Count number of rows for TWO QUERIES USING MINUS OPERATOR
I have the following piece of sql, i would like to know how could i programatically using plsql count the number of rows returned by the following statement. I know that %ROWCOUNT returns the rowcount for the last execute INSERT, UPDATE, DELETE and S
-
FSCM-COL: Worklist functionalities
Hi all, I have another quick question regarding the Worklist functionality that Iu2019m hoping that you guys could clarifyu2026 In the tab u201CInvoicesu201D I have a couple of fields: -u201CPaidu201D u2013 That corresponds to amount paid (Data Eleme
-
I purchased and downloaded "The Italian Job (2003)" to my iTunes and iPod. However, whenever I try to play the movie, I get to the end of the opening credits and the movie stops. My iTunes tells me that I have an error and I exit the application. On