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

Need to convert ExecuteQuery result into an array of JSON object

Avatar

Level 2

Hi All, 
I am trying to execute a query on one my ACC tables. I need to create an array of Json objects . Can someone help to do it dynamically if he has already done in the past

Table Structure : 

CountryService1Service2Service3
IndiaYesNoNo
MalaysiaNoYes Yes

 

Output that I am looking for :

[

{ Country:"India",

Service1:Yes

Service2:No

Service3:No},

{ Country:"Malaysia",

Service1:No

Service2:Yes

Service3:Yes}

]

 

@david--garcia 

Thanks

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @rahulg12032086 

 

You can try the below code for your requirement.

 

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);    
logInfo(schemaName);  
var query = xtk.queryDef.create(    
  <queryDef schema={vars.targetSchema} operation="select">    
    <select>    
      <node expr="@country"/>    
      <node expr="@Service1"/>    
	  <node expr="@Service2"/> 
	  <node expr="@Service3"/> 
    </select>    
  </queryDef>    
);    
var resultSet = query.ExecuteQuery();    
var Data='';
for each (var row in resultSet) 
{
	Data= Data +
	"{
		Country ="+row.@country;
		"Service="+row.@Service1;
		"Service="+row.@Service2;
		"Service="+row.@Service3;
	"}";
}
Data="["+Data+"]";
logInfo(Data);

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @rahulg12032086 

 

You can try the below code for your requirement.

 

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1);    
logInfo(schemaName);  
var query = xtk.queryDef.create(    
  <queryDef schema={vars.targetSchema} operation="select">    
    <select>    
      <node expr="@country"/>    
      <node expr="@Service1"/>    
	  <node expr="@Service2"/> 
	  <node expr="@Service3"/> 
    </select>    
  </queryDef>    
);    
var resultSet = query.ExecuteQuery();    
var Data='';
for each (var row in resultSet) 
{
	Data= Data +
	"{
		Country ="+row.@country;
		"Service="+row.@Service1;
		"Service="+row.@Service2;
		"Service="+row.@Service3;
	"}";
}
Data="["+Data+"]";
logInfo(Data);