Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!
SOLVED

ACC nmsSeedMember counter

Avatar

Community Advisor

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

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 4

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.

Avatar

Community Advisor

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?

Avatar

Level 4

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

 

Avatar

Correct answer by
Community Advisor

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();

}