Making a Query in Salesforce Using SSJS
Saleforce allows you to execute queries using a technology that resembles JavaScript. It is possible to work with JSON. And the results can be passed back to AMPscript. Requests are executed on the server side
%%[
SET @infoblockId = RequestParameter("offerId")
]%%
<script runat="server">
Platform.Load("Core", "1")
var infoblockId = Variable.GetValue("@infoblockId");
var payload = {infoblockId: infoblockId};
//create request
var req = new Script.Util.HttpRequest('https//site.example/?param=some');
req.emptyContentHandling = 0
req.retries = 2
req.continueOnError = true
req.contentType = 'application/json'
req.method = "POST"
req.postData = Stringify(payload);
var res = req.send();
var respStatusCode = res.statusCode
//if error
if (respStatusCode != 200) {
Variable.SetValue("@getRequest",{});
return
}
//if success
Variable.SetValue("@getRequest",res.content);
//convert to JSON for special manipulation
var resultJSON = Platform.Function.ParseJSON(String(res.content));
var count = resultJSON.totalCount
Variable.SetValue("@getcount",count);
</script>