Skip to main content
Added in working code after implementing Adam's suggestion
Source Link
Gortonington
  • 30.8k
  • 3
  • 27
  • 64

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);

Below is the final SSJS that worked:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest");

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtension.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "DataExtension.CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Stringify(Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID));

//Check Status
var status = StatusAndRequestID[0];
var requestID = StatusAndRequestID[1];

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);

Below is the final SSJS that worked:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest");

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtension.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name");

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "DataExtension.CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Stringify(Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID));

//Check Status
var status = StatusAndRequestID[0];
var requestID = StatusAndRequestID[1];
added 668 characters in body
Source Link
Gortonington
  • 30.8k
  • 3
  • 27
  • 64

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest") 

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType","DataExtensionField["+DE+"]" "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "Name""DataExtensionField.Name"); 

//Create a filter
var StatusAndRequestIDRetrieveFilter = [0Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter,0]; "Property", "CustomerKey")
var Result =  Platform.Function.InvokeRetrieveSetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject,StatusAndRequestID "Filter", RetrieveFilter);

//Do the retrieve
var statusStatusAndRequestID = StatusAndRequestID[0];[0,0];

var requestIDResult = StatusAndRequestID[1];Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType","DataExtensionField["+DE+"]");
     
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "Name");

var StatusAndRequestID = [0,0];
var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);
var status = StatusAndRequestID[0];
var requestID = StatusAndRequestID[1];

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

Platform.Load("core","1");

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest") 

//Set the request type
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType", "DataExtensionField");
    
//Set the columns
     Platform.Function.AddObjectArrayItem(retrieveObject,"Properties", "DataExtensionField.CustomerKey");
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "DataExtensionField.Name"); 

//Create a filter
var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");

//By CustomerKey
    Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "CustomerKey")
    Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator","Equals")
    Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", DE )

//add filter to the retrieve
Platform.Function.SetObjectProperty(retrieveObject, "Filter", RetrieveFilter);

//Do the retrieve
var StatusAndRequestID = [0,0];

var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);
Source Link
Gortonington
  • 30.8k
  • 3
  • 27
  • 64

SSJS web API retrieve Column Names

I know this can be done via SOAP or an SDK, but I have a specific need to have this done in Marketing Cloud SSJS interacting with Web API (on a landing page, not in an email).

The aim is to create a retrieve object that pulls only the column names of a data extension and none of the values. The result should be a JSON file that only contains the column name - eg ["Email","FirstName","LastName"].

I constantly receive an error or a blank payload on each RetrieveRequest I put in. I feel like it is something small or silly that I am doing wrong.

See below for SSJS snippet I am using:

var DE = dataextensionIdentifier

var retrieveObject = Platform.Function.CreateObject("RetrieveRequest")
Platform.Function.SetObjectProperty(retrieveObject,"ObjectType","DataExtensionField["+DE+"]");
     
     Platform.Function.AddObjectArrayItem(retrieveObject, "Properties", "Name");

var StatusAndRequestID = [0,0];
var Result = Platform.Function.InvokeRetrieve(retrieveObject,StatusAndRequestID);
var status = StatusAndRequestID[0];
var requestID = StatusAndRequestID[1];