DEV101 Javascript Controllers Quickcard 8-19-2016
DEV101 Javascript Controllers Quickcard 8-19-2016
Controllers QuickCard
Import an Object Displaying a Form (Equivalent of ICN node)
var ISML = require('dw/template/ISML'); ISML.renderTemplate(
'editpreferences.isml',
var guard = require('storefront_controllers/cartridge/scripts/guard');
{
ContinueURL : dw.web.URLUtils.https('JEditPreferences‐
Function Declaration and Exposure HandleForm'),
function start() { CurrentForms : session.forms
} }
exports.Start = guard.ensure([ 'get'], start); );
exports.Start = guard.ensure([ 'get', 'https', 'loggedIn' ], start);
Submit Button
Dealing with Query Parameters var submitButton =
var parameterMap = request.httpParameterMap; request.triggeredFormAction.formId;
var parameterId =parameterMap.pid.stringValue;
Writing to Browser Directly
Handling Forms response.getWriter().println(“Hello from controllers”);
/* assuming forms/default/preferences.xml is the metadata */
var preferencesForm = session.forms.preferences; Explicit Transactions
preferencesForm.clearFormElement(); var Transaction= require('dw/system/Transaction);
preferencesForm.copyFrom(customer.profile); Transaction.begin();
preferencesForm.copyTo(customer.profile); Transaction.commit();
preferencesForm.interestElectronics.value; Transaction.rollback();
preferencesForm.invalidateFormElement();
Redirecting to Another Pipeline
Giving Control to ISML (Equivalent of Interaction node) response.redirect(URLUtils.https('Account‐Show'));
ISML.renderTemplate(
'productnotfound.isml',
{ Invoking a Script (js or ds)
message:'product'+parameterId+'found' var myModel = require('~/cartridge/scripts/MyModel');
} var co=myModel.doJobForMe(takeThisObject);
);
© 2016 Demandware, Inc. DEV 101: Developing in Demandware