- Can I process an SSJS AMPscript?
- If I receive a string "AMPscript" can I give it a context and SSJS will process it?
- in the provided code I am trying to take a string like this
%%=FormatDate([transaction_datetime], 'dd/MM as','hh:mm')=%%
and process it with the data obtained from the Data Extension
<script runat="server">
Platform.Load("Core", "1.1.5");
var externalKey = "EXTERNAL_KEY_DE";
try {
if (Request.Method == "POST") {
var payload = Platform.Request.GetPostData("UTF-8");
var jsonObject = Platform.Function.ParseJSON(payload);
// String Ampscript
var myString = jsonObject.ampscript;
var deNotifications = DataExtension.Init(externalKey);
var filter = {
LeftOperand: {
Property: "notification_id",
SimpleOperator: "equals",
Value: jsonObject.notification_id
},
LogicalOperator: "AND",
RightOperand: {
Property: "customer_id",
SimpleOperator: "equals",
Value: jsonObject.customer_id
}
}
var columns = [
"transaction_datetime",
"transaction_placeofuse_name",
"transaction_total_amount"
];
var testeDE = deNotifications.Rows.Retrieve(filter, columns);
if (testeDE.length > 0) {
var notification = testeDE[0];
var ampscriptContext = {
"transaction_datetime": notification.transaction_datetime,
"transaction_placeofuse_name": notification.transaction_placeofuse_name,
"transaction_total_amount": notification.transaction_total_amount
};
var ampscriptprocessed = Platform.Function.Execute(myString, ampscriptContext);
Platform.Response.Write("AMPSCRIPT " + ampscriptprocessed);
} else {
Platform.Response.StatusCode = 404;
}
Platform.Response.Write("myString: " + testeDE.length);
} else {
Platform.Response.StatusCode = 400;
}
} catch (ex) {
Platform.Response.StatusCode = 500;
}
</script>
Platform.Function.Execute
from?