Mobile App: Producing a warning box to confirm the changing of a boolean's value.

Hi Community, 

 

I have written a business rule that, when a boolean field has been set to true in the mobile app, stores the current timestamp in another separate date/time field: 

 

Terrasoft.sdk.Model.addBusinessRule("Activity", {
    name: "SetTimestampOnCheckForTriggeredField",
    ruleType: Terrasoft.RuleTypes.Custom,
    triggeredByColumns: [
        "InnEndSiteVisitCheck", "InnEndTravelInCheck", "InnEndTravelOutCheck",
        "InnStartSiteVisitCheck", "InnStartTravelInCheck", "InnStartTravelOutCheck"
    ],
    events: [Terrasoft.BusinessRuleEvents.ValueChanged],
 
    executeFn: function(record, rule, column, customData, callbackConfig) {
        // Mapping of boolean fields to their corresponding date-time fields
        var fieldMapping = {
            "InnEndSiteVisitCheck": "InnEndSiteVisitTime",
            "InnEndTravelInCheck": "InnEndTravelInTime",
            "InnEndTravelOutCheck": "InnEndTravelOutTime",
            "InnStartSiteVisitCheck": "InnStartSiteVisitTime",
            "InnStartTravelInCheck": "InnStartTravelInTime",
            "InnStartTravelOutCheck": "InnStartTravelOutTime"
        };
 
        // Get the boolean value of the triggered field
        var isCheckTrue = record.get(column);
 
        // Check if the boolean field is true
        if (isCheckTrue && fieldMapping[column]) {
            // Set the corresponding date-time field to the current date/time
            var currentDateTime = new Date();
            record.set(fieldMapping[column], currentDateTime);
        }
 
        // Asynchronous callback to indicate the rule has been processed
        Ext.callback(callbackConfig.success, callbackConfig.scope, [true]);
    }
});

 

I now want to be able to show a warning message that gives an option to 'cancel' or 'confirm' when a user attempts to set one of these booleans to false. 

 

The box would need to be shown after an attempt to change the booleans value, halting this action until confirmed  - if the action is not prevented before confirmation and the 'cancel' option merely reverts the boolean to being true, the old timestamp would be lost with the new value being representative of the time of cancellation (which is not what I desire).

 

The following post presents a similar requirement: Pop-up with options in mobile application | Community Creatio

 

However, guidance given points to a push notification (which I can't envision helping as I require an option in the app that temporarily halts the setting of the boolean to false), or to use Terrasoft.MessageBox.showMessage, which from what I can tell can only produce a message box (no option to cancel or confirm). 

 

I have also thought about writing individual rules that set each field to be disabled once it has been checked:

 

// Disable the InnEndSiteVisitCheck field after it is checked
Terrasoft.sdk.Model.addBusinessRule("Activity", {
    name: "DisableInnEndSiteVisitCheck",
    ruleType: Terrasoft.RuleTypes.Activation,
    triggeredByColumns: ["InnEndSiteVisitCheck"],
    events: [Terrasoft.BusinessRuleEvents.Load, Terrasoft.BusinessRuleEvents.ValueChanged],
    conditionalColumns: [
        { name: "InnEndSiteVisitCheck", value: true }
    ],
    dependentColumnNames: ["InnEndSiteVisitCheck"]
});

 

However, this is not as flexible as I would want as users may set field values to true by mistake. Even then, the rule I have written does not seem to work as I get a server error when syncing in the mobile app after adding it - perhaps this is because two rules are initiated by the same event? 

Any help on this would be greatly appreciated, thanks in advance!

Like 1

Like

2 comments
Best reply

Hello,

 

Terrasoft.MessageBox also contains the showConfirmation method that can be called to show the confirmation box:

Also you can specify the callback function that will be called upon clicking the "confirm" button (using the yesCallback function inside the object that is passed as an argument into the showConfirmation method or "negative" button (the noCallback function should be created). So you can use it in your development.

Hello,

 

Terrasoft.MessageBox also contains the showConfirmation method that can be called to show the confirmation box:

Also you can specify the callback function that will be called upon clicking the "confirm" button (using the yesCallback function inside the object that is passed as an argument into the showConfirmation method or "negative" button (the noCallback function should be created). So you can use it in your development.

Hi Oleg,

 

Thanks for your reply, this has helped to develop a solution!

Show all comments