In this post, we will cover how to use WSProxy in SSJS when dealing with Data Filters in Salesforce Marketing Cloud.
Before starting off, let's understand some of the basics of Data Filter and WSProxy.
What is a Data Filter?
Data Filters are used to filter the data based on either of the below options:
1. Profile/Preference Attributes
2. Data Extension
Once the filter is set up, a Data Extension can be created from it or it can also be scheduled using the 'Automation Studio Filter Activity' in order to automate the process so that the data is up-to-date.
What is WSProxy?
WSProxy is an object that is native to Salesforce Marketing Cloud and is used in non-sendable environments. It is used to interact with the available SOAP objects, to increase the speed of the API calls, and is a part of the SSJS Platform library.
Why use WSProxy?
Using the legacy SSJS methods in the Core library adds an overhead to the processing of the calls, due to which WSProxy is a better option.
How to use WSProxy?
To utilize WSProxy, the below line of code needs to be added for creating an object to handle the proxying of calls.
var prox = new Script.Util.WSProxy();
Now, let's go through each of the following where we use the 'FilterDefinition' object that represents a Data Filter in SSJS.
Describe a Data Filter
Describe call can be used when you need information about the structure of a SOAP API object.
Retrieve the data for a Data Filter
Retrieve all the information about a Data Filter by specifying the required columns and the 'External key.'
Note: Not all the columns that are present in the result of a Describe call are retrievable.
Delete a Single Data Filter
To delete a Data Filter use the 'deleteItem' function and the ObjectID.
Delete Multiple Data Filters
To delete multiple Data Filters - Create an array, iterate through each item in an array, and then use the 'deleteItem' function.
Create a Data Filter with a Single filter condition
Create a Data Filter using the 'createItem' function with a single filter condition.
In the below example, we create using a filter condition 'Points > 0'.
Create a Data Filter with Multiple filter conditions
Create a Data Filter using the 'createItem' function with multiple filter conditions.
In the below example, we create using a filter condition 'Points > 0' and 'Centre equals abc.'
Move a Data Filter
Move a Data Filter from one folder to another by specifying the 'CategoryID' and using the 'updateItem' function.
Update a Data Filter
Update a Data Filter using the 'updateItem' function. In the below example, we are updating the name of the Data Filter.
Things to Note -
1. Syntax for creating a Data Filter is different than that of Data Extensions. The use of simple operators such as isNull and isNotNull does not work when defining a filter condition but as a workaround, you can use 'equals' and 'notEquals' with a value of NULL("").
2. Moving and updating a Data Filter requires the use of the same function i.e., 'updateItem'.
3. Deleting a Data Filter can also be done by specifying the External Key, instead of a Name.
4. To find the Category ID & Object Name - Hover over any of the Folders and check the bottom-left of the page.
To learn more about WSProxy, check out the below two articles:
1. Article by Greg Gifford
2. Article by Eliot Harper
To learn how to work with Data Extensions using WSProxy, check out this article by Ivan Razine.
Hope you enjoyed it! Please feel free to contact me with any feedback/suggestions.
See you in the next one!
Comentários