Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

ACC nmsSeedMember counter

David__Garcia
Level 8
Level 8

Hi Experts,

 

There is a counter which is used as part of an expression when creating new seeds.

 

david_garcia1_2-1625834170358.png

 

 

david_garcia1_1-1625831243433.png

 

I am trying to get the seed counter value to no avail.

 

var seedKey = 'SDM'+CounterValue('nmsSeedMember');
logInfo(seedKey);

 

david_garcia1_3-1625834259669.png

 

 

Counter javascript nmsSeedMember seeds
1 Accepted Solution
David__Garcia
Correct answer by
Level 8
Level 8

Solution:

var query = xtk.queryDef.create(
<queryDef schema={vars.targetSchema} operation="select">
<select>
  <node expr="@lineNum"/>
</select>
</queryDef>
);

var result = query.ExecuteQuery();

var data = NLWS.xtkCounter.load(2521030); //id of counter
var c = data.value;

for each(var i in result) {

c++
data.value = instance.vars.c = c;

sqlExec("UPDATE  " + vars.tableName + " SET sInternalName = 'SDM"+instance.vars.c+"' WHERE iLineNum="+i.@lineNum);
data.save();

}

 

View solution in original post

4 Replies
Krishnanunni
Level 3
Level 3

Hi @David__Garcia ,

I don't think the CounterValue function can be used inside JavaScript. You may use querydef to fetch the value 

var query = xtk.queryDef.create(
<queryDef schema="xtk:counter" operation="select">
<select>
<node expr="@name"/>
<node expr="@value"/>
</select>
<where>
<condition expr="@name= 'nmsSeedMember'"/>
</where>
</queryDef>
);

var resultSet = query.ExecuteQuery();
for each (var row in resultSet.*) {
logInfo(row.@name + " = " + row.@value )
}

Or you can use SOAP API to get incremented value of counter using this function.

David__Garcia
Level 8
Level 8

I scripted the following which loads the current value and also sets it.

 

var data = NLWS.xtkCounter.load(2521030); //id of counter
var c = data.value;
//logInfo(c+ " " +typeof c);
data.value = ++c;
data.save()

 

Now I guess I need to integrate it into the expression or some kind of loop, any ideas?

Krishnanunni
Level 3
Level 3

Hi @David__Garcia ,

Once you have the value in JavaScript, save it to an instance variable and then you can use in expression using $(instance/vars/xxx) format.

Krishnanunni_0-1626068099560.png

 

David__Garcia
Correct answer by
Level 8
Level 8

Solution:

var query = xtk.queryDef.create(
<queryDef schema={vars.targetSchema} operation="select">
<select>
  <node expr="@lineNum"/>
</select>
</queryDef>
);

var result = query.ExecuteQuery();

var data = NLWS.xtkCounter.load(2521030); //id of counter
var c = data.value;

for each(var i in result) {

c++
data.value = instance.vars.c = c;

sqlExec("UPDATE  " + vars.tableName + " SET sInternalName = 'SDM"+instance.vars.c+"' WHERE iLineNum="+i.@lineNum);
data.save();

}

 

View solution in original post