AnsweredAssumed Answered

Script trouble automating values for new attribute for existing records

Question asked by cthor on Sep 6, 2017
Latest reply on Sep 18, 2017 by roland.parrotte

Hi all, first time i'm attempting this, so any help would be appreciated.

We created  new attribute for an existing object, and would like to auto-populate the existing records with an incremented value.  I'm trying to write a process (would be run just the one time) to auto-fill the existing records with something like "ID-0000n" where n will increment for each record I update through the script.  Once completed I would turn the auto-number for the attribute on so that any new records will start with an ID following this pattern.

My incorrect script is as follows:

 

<gel:script xmlns:core="jelly:core" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" xmlns:sql="jelly:sql" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <gel:setDataSource dbId="Niku"/>
  <core:set value="00001" var="myCount"/>

  <sql:query escapeText='false' var='myObject'>
    select *
    from odf_ca_some_object temp
    <core:forEach trim='true' items='${myObject.rows}' var='row'>
      <core:set value="${myObject.code}" var="myID"/>
      <sql:update>
          update odf_ca_some_object
          set theNewAttribute = myCount
          where (id = ${myID})
      </sql:update>
      set myCount = myCount + 1
    </core:forEach>
  </sql:query>

</gel:script>

 

Any help would be greatly appreciated.  And i'm fairly new to both SQL and GEL scripting if you couldn't already tell

Outcomes