Clarity

  • 1.  How to clear a Variable in Gelscript

    Posted Jan 25, 2016 02:04 AM

    Hello Everyone,
    Here I am Using clear function for a Variable but its not working.

     

    <gel:script

    xmlns:core="jelly:core"

    xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"

    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

     

        <core:forEach begin="1" end="2"  var="test">   

       

    <file:readFile fileName="D:\Gel Script Docs\JS Custom Scripts\test.csv" embedded="false"

    var="input"/>

    <gel:out>  ${test} Input has ${input.size()} rows.</gel:out>

     

        <core:forEach begin="1" end="4" indexVar="i1" items="${input.rows}" var="row">   

        <gel:out>IndexVar ---------------${i1}</gel:out>

        <gel:out>q Username = ${row[0]}</gel:out>

       

    <gel:out>First = ${row[1]}</gel:out>

    <gel:out>Last = ${row[2]}</gel:out>

        </core:forEach>

       

        <gel:out>132 ${input.clear()} </gel:out>

        </core:forEach>

    </gel:script>

     

    When i run this script
    For the First time forEach Iteration it shows 1 Input has 4 rows

    for the Second time forEach Iteration it shows 2 inout has 8 rows
    It means Clear is not working

     

    could you help me out How to use Clear.

    Thanks.



  • 2.  Re: How to clear a Variable in Gelscript

    Posted Jan 25, 2016 02:56 AM


  • 3.  Re: How to clear a Variable in Gelscript
    Best Answer

    Posted Jan 25, 2016 03:39 PM

    A defect had been created for this previously (#clrt-70265 "GEL file library tag readFile retains and accumulates old data when reading from multiple files") but it was not something that any customers had encountered or reported.

     

    Could you please raise a support ticket for this, indicate your product version that this is affecting you on, and give the above reference?

     

    The following was given to describe a workaround of sorts at the time (it is not trivial or straight forward):

     

    Revise the algorithm into 2 loops, one to iterate over the files and accumulate the data into the rows array (storing separately the quantity of rows in each if needed), and the other to then iterate once over the final set of file rows all together.

     

     

    Note that this workaround would need to be removed again if the defect is fixed as the lack of data accumulation would then mean it is no longer aggregated, by reverting the algorithm to an outer loop of files being read and an inner loop iterating over the rows for just that file.

     

    I don't know if that helps in the meantime, but the storage mechanism used in the tag for the data isn't exposing methods for clearing/resetting, so it appears to need to be another way required like this workaround.