A Newsletter controller contains the following route:
Server.post(‘Subscribe’, function (req,res,next){
var newsletterForm = server.forms.getForm(‘newsletter’);var CustomObjectMgr =
require(‘dw/object/CustomObjectMgr’);
if(newsletterForm.valid){ try{
var CustomObject =
CustomObjectMgr.createCustomObejct(‘NewsletterSubscription’, newsletterform.email.value); CustomObject.custom.firstName = newsletterForm.fname.value;
CustomObject.custom.lastName = newsletterForm.lname.value;-
} catch(e){
//Catch error here
}
}
next();
});
Assuming the Custom Object metadata exists, why does this route fail to render the newsletter template
when the subscription form is correctly submitted?
- Custom Objects can only be created by Job scripts
- The Subscribe route is missing the server.middleware.httpt middleware.
- The CustomObjectMgr variable should be declare outside of the route.
- The Custom Object creation is not wrapped in a Transaction.
Reveal Solution Next Question