How to make a field required based on some condition in mobile app?

Hi Community,

 

Below  is the business rule I need to apply

 

Below is the code I wrote 

 

This doesn't work in mobile app but it also is not throwing any error.

 

Can anyone help me with this issue!

 

Many Thanks,

 

Akshit.

Like 0

Like

1 comments

Hi Akshit,

 

Here is an example of the code that has perfectly worked on my end:

Terrasoft.sdk.Model.addBusinessRule("Case", {
    name: "Make UsrStringField column required",
    ruleType: Terrasoft.RuleTypes.Custom,
    triggeredByColumns: ["UsrBoolAct"],
 
    events: [Terrasoft.BusinessRuleEvents.ValueChanged, Terrasoft.BusinessRuleEvents.Save],
 
    executeFn: function(record, rule, column, customData, callbackConfig) {
    	var isRequired;
    	var isActivated = record.get("UsrBoolAct");
    	if (isActivated===true){
    		isRequired=false;
    	} else {
    		isRequired=true;
    	}
        record.changeProperty("UsrStringField", {
            isValid: {
                value: isRequired,
                message: "Column must be filled in"
            }
        });
 
        Ext.callback(callbackConfig.success, callbackConfig.scope, [isRequired]);
    }
});

The logic here is that the "UsrBoolAct" column is true (this is a boolean column) then the "UsrStringField" should be filled in. After the application pool was restarted this output was received:

Please also note that wen workig with lookups instead of booleans such a construction will help to achieve the result needed:

var type = record.get("Type");
        if (type && (type.get("Id") === Terrasoft.ContactTypes.Doctor ||
                type.get("Id") === Terrasoft.ContactTypes.ContactPerson))

Best regards,

Oscar

Show all comments