Here is a template if anyone needs this functionality further:
This will override the default behaviour of saving to localStorage and rather persist to server.
<script cam-script type="text/form-script">
inject(['$http', 'Uri', function ($http, Uri) {
camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('customerApplication');
});
camForm.on('variables-fetched', function() {
$scope.customerApplication = camForm.variableManager.variable('customerApplication').value;
});
camForm.on('store', function(evt) {
camForm.variableManager.variable('customerApplication').value = $scope.customerApplication;
storeVariablesToEngine(evt)
});
camForm.on('submit', function() {
camForm.variableManager.variable('customerApplication').value = $scope.customerApplication;
});
function storeVariablesToEngine(evt) {
evt.retrieveVariables();
var varManager = evt.variableManager;
var vars = varManager.variables;
var variableData = {};
for (var v in vars) {
if (varManager.isDirty(v)) {
var val = vars[v].value;
if (varManager.isJsonVariable(v)) {
val = JSON.stringify(val);
}
variableData[v] = {
value: val,
type: vars[v].type,
valueInfo: vars[v].valueInfo
};
}
}
var data = { modifications: variableData };
var config = {
headers: {
'Content-Type': 'application/json'
}
};
$http.post(Uri.appUri('engine://engine/:engine/task/' + camForm.taskId + '/variables'), data, config);
evt.storePrevented = true;
}
}]);
</script>