himani.sharma

Need help with for each loop i insert just one record

Discussion created by himani.sharma on Nov 25, 2010
Latest reply on Nov 26, 2010 by himani.sharma
Now i can only xog one record i dont understand what shouldi chage in the script

<gel:script xmlns:core="jelly:core"
xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
xmlns:q="http://www.niku.com/xog/Query"
xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="jelly:sql" xmlns:util="jelly:util" xmlns:x="jelly:xml"
xmlns:xog="http://www.niku.com/xog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<gel:setDataSource dbId="Niku"/>
<gel:parameter default="avenir" var="XOGUsername"/>
<gel:parameter default="Clarity01" secure="true" var="XOGPassword"/>
<gel:parameter default="localhost" var="XOGURL"/>
<gel:out>URL: ${XOGURL}</gel:out>


<!--=====================LOGIN========================================-->


<soap:invoke endpoint="http://${XOGURL}/niku/xog" var="auth">

<soap:message>

<soapenv:Envelope

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog">

<soapenv:Header/>

<soapenv:Body>

<xog:Login>

<xog:Username>${XOGUsername}</xog:Username>

<xog:Password>${XOGPassword}</xog:Password>

</xog:Login>

</soapenv:Body>

</soapenv:Envelope>

</soap:message>

</soap:invoke>

<!--=====================LOGIN ENDS========================================-->

<gel:out>login OK </gel:out>
<!--=====================PULLing OUT SESSION ID and creating a log========================================-->

<gel:set var="sessionId" select="$auth//xog:SessionID/text()" asString="true" />

<core:if test="${sessionId==null}">
<gel:out>unable to log on to the XOG. Probably the username and password parameters</gel:out>



</core:if>

<gel:out>Connection successful,${sessionId}</gel:out>

<!--=====================main block========================================-->

<!--The string variable new_ress stores the data from the table odf_ca_edb_import_resurs -->
<gel:out>SQL called</gel:out>


<sql:query var="new_ress">
SELECT ress.name, edb_last_name, edb_email_address, edb_dept,edb_employee_type,edb_manager_id,edb_resource_id
FROM odf_ca_edb_import_resurs ress

select count (*) from niku.ODF_CA_EDB_IMPORT_RESURS


</sql:query>


<gel:out>SQL returns: ${new_ress}</gel:out>


<core:forEach trim="true" items="${new_ress.rowsByIndex}" var="row">


<!-- FOREACH LOOP from here on rows[x] -->



<core:set value="{row[6]}" var="MyFirstName"/>

<core:set value= "{row[9]}" var="MyLastName"/>

<core:set value="{row[10]}" var="MyEmail"/>

<core:set value="{row[11]}" var="Mydept"/>

<core:set value="{row[12]}" var="Myemptype"/>

<core:set value="{row[13]}" var="Mymgrid"/>

<core:set value="{row[14]}" var="Myresid"/>


<gel:out>First name: ${MyFirstName} / Last_name: ${MyLastName} / email: ${MyEmail} / dept: ${Mydept} </gel:out>

<gel:out> emptype: ${Myemptype} / mgrid: ${Mymgrid} /empid: ${Myresid} </gel:out>





<!--in the message whatever u want to be pulled out to console u hv to put it as ${variable name} -->
<!--in the message whatever u want to be pulled out to console u hv to put it as ${variable name} -->
<!--The TABLE in clarity from which the data is fetched-->

<!--value = new_ress is the name of the variable-->
<!--The variables that need to be selected from the table -->

<!--=====================PARSING AND autoupdate employees========================================-->


<gel:out>Parsing start</gel:out>
<gel:parse var="v_xml_ress">












<NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/nikuxog_resource.xsd">
<Header action="write" externalSource="NIKU" objectType="resource" version="8.1.0.03.4373"/>
<Resources>
<Resource resourceId="${Myresid}" isActive="true" employmentType="Myemptype" resourceType="LABOR" managerUserName="${Mymgrid}" externalId=" " >

<PersonalInformation displayName="${MyLastName}" emailAddress="${MyEmail}" firstName="${MyFirstName}" lastName="${MyLastName}"/>
<ManagementInformation trackMode="clarity" openForTimeEntry="true" inputTypeCode="STANDARD"/>
<CustomInformation>
<ColumnValue name="partition_code">NIKU.ROOT</ColumnValue>
</CustomInformation>
<FinancialInformation>
<SupplementalInformation location="Avenir" department="${Mydept}" resourceClass="STANDARD" transactionClass="STANDARD"/>
</FinancialInformation>
<General addedBy="Avenir"/>
<SkillAssocs/>
<Calendar baseCalendar="Standard" resetCalendar="false"/>


<gel:out> ${MyFirstName} / ${MyLastName} / ${MyEmail} / ${Mydept} </gel:out>

<gel:out> ${Myemptype} / ${Mymgrid} / ${Myresid} </gel:out>

<gel:out>deptID: ${Mydept}</gel:out>
</Resource>
</Resources>

</NikuDataBus>
</gel:parse>


<gel:out>Parsing finish </gel:out>

<!-- =====================================================
XOG write to clarity this needs to be added after parsing
===================================================== -->
<!-- <core:catch var="exception"> -->
<soap:invoke endpoint="http://${XOGURL}/niku/xog" var="xog_ress_log">
<soap:message>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog">
<soapenv:Header/>
<soapenv:Body>
<SessionID>${sessionId}</SessionID>





<!--=======The parameter to include is the one we used in parse look at the first line in parse here it is v_xml_ress=-->




<gel:include select="$v_xml_ress"/>





</soapenv:Body>
</soapenv:Envelope>
</soap:message>
</soap:invoke>
<!-- </core:catch> -->

<!-- Checking whether a sessionID is returned. If not, it means that Login was unsuccessful
<gel:set asString="true"
select="$xog_ress_log//XOGOutput/Status/@state" var="xogReadState"/>
<gel:out>Reading template via XOG ${xogReadState}</gel:out>
<core:if test="${xogReadState=='FAILURE'}">
<gel:out>Error reading template</gel:out>
</core:if>
<gel:serialize fileName="xog_ress_log" var="${xog_template}"/>


-->



</core:forEach>

<!--=====================LOGGING OUT OR DISCONNECTING========================================-->
<gel:out>Disconnecting from xog</gel:out>


<core:catch var="exception">

<soap:invoke endpoint="http://${XOGURL}/niku/xog" var="auth">


<soap:message>



<soapenv:Envelope>



<soapenv:Body>




<Logout xmlns="http://www.niku.com/xog">





<SessionID>${sessionId}</SessionID>




</Logout>



</soapenv:Body>



</soapenv:Envelope>


</soap:message>

</soap:invoke>

</core:catch>
<!-- throw an error if the disconnection was unsuccessfull. -->
<core:if test="${exception!=null}">
<gel:out>Error disconnecting from XOG ${exception}</gel:out>
</core:if>
<!--=====================LOGGING OUT OR DISCONNECTING=block ends=======================================-->

</gel:script>

Outcomes