Override the Default Save Mechanism
The default save method on forms saves into the database the data inserted by users when filling in the forms. If you want to manipulate the data before saving it into the database, you can do so by overriding the default save method.
Overriding the default save method on data form is also useful if the current user does not have privileges on that entity. You can achieve this on the server side by using an endpoint (action) in three steps:
1 Create an On-Demand Automation Script
This is the script that will be executed instead of the default save function. For information on how to create on-demand automation scripts, see Create On-demand Server Automation Scripts .
If you want to override the save on forms exposed to unauthenticated users, use this minimal working code in the on-demand script.
setAdminMode(true);
//log(context);
var activeStatus = getOptionSetItemId("B2CProcessStatus", "Active");
var entityIdByName = getEntityIdByName(context.EntityName);
var dateName = new Date().toString();
var sessId = server.B2C.SessionId;
var saveData = getEndpointSaveData();
saveData.EntityValues["formName"] = saveData.FormName;
saveData.EntityValues["sectionIndex"] = saveData.SectionIndex;
saveData.EntityValues["sectionName"] = saveData.SectionName;
if(saveData.OperationType == "edit"){
update(saveData.EntityName, saveData.Id, saveData.EntityValues);
}
else if(saveData.OperationType == "insert"){
var generatedId = insert(saveData.EntityName, saveData.EntityValues);
setData({"Id": generatedId});
var epVals = {
"sessionId": sessId,
"name": dateName,
"entityId": entityIdByName,
"recordId": generatedId,
"status": activeStatus
}
var B2CExternalProcessId = insert("B2CExternalProcess", epVals);
}
function getEntityIdByName(name){
var a = getByQuery({
entity: {name: "entity", alias: "a"},
where: {
type: "and",
conditionlist: [{
type: "equals",
first: "a.name",
second: "val(" + context.EntityName + ")"
}]
}
});
return a[0]["a_entityid"];
}
Where:
saveData.EntityValues
contains the values that will normally be passed to the default save function.- FintechOS uses the
sessionId
parameter to retrieve the desired record through the B2C External Process entity.
2 Create an Endpoint and Attach the Script to it
Create an endpoint (action) and add the automation script created at step 1 to it.
For information on how to create and endpoint and attach an automation script to it, see Endpoints.
3 Call the Endpoint on the Form Driven Flow
In the Before Events of the form driven flow, call the setSaveEndpoint
method of the formData
object, with the name of the endpoint created at step 1:
formData.setSaveEndpoint("endpointName");
When overriding the default save functionality, you can use the formData.getEndpointSaveData()
method to retrieve the entity save data and other save context information. This function returns an IEndpointSaveData object:
interface IEndpointSaveData
{
Id: string;
EntityName: string;
OperationType: "edit" | "insert";
FormName: string;
SectionIndex: number;
SectionName: string;
EntityValues: any;
}