Overriding Default Save on Journeys

The default save method on forms will save into the database the data inputted by the user when completing the data form.

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 by using an endpoint (action) in three simple steps:

STEP 1. Create an on-demand automation script

This script will be executed instead of the default one. For information on how to create on-demand automation scripts, see Create On-demand 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
Copy
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 relies on the sessionId parameter to retrieve the desired record through the B2C External Process entity.

STEP 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 Create an Endpoint.

STEP 3. Call the endpoint on the form driven flow

In the Before Events of the form driven flow, call the setSaveEndpoint function of the formData object, with the name of the endpoint created at step 1:

Copy
formData.setSaveEndpoint("endpointName");

Function getEndpointSaveData()

When overriding the default save functionality using an endpoint, the function retrieves the entity save data and other save context information.

Returns: IEndpointSaveData

Copy
interface IEndpointSaveData
{
    Id: string;
    EntityName: string;
    OperationType: "edit" | "insert";
    FormName: string;
    SectionIndex: number;
    SectionName: string;
    EntityValues: any;
}