Question

Field Validations on detail page

Hi,

 

I have to implement validations on the editable detail of a section. For the purpose, I am using addRecord

But while I am trying to get the value of the lookup field which is connecting the records to the main section, it is returning undefined.

 

Please refer below code:

addRecord: function()

{

     this.DurationValidation();

     this.callParent(arguments);

}
DurationValidation : function()
            {
                var invalidMessage="";
                try
                {
                     var esqDuration = this.Ext.create("Terrasoft.EntitySchemaQuery", {
                    rootSchemaName: "UsrPRDetail"
                });
                esqDuration.addColumn("UsrDurationmin");
                var groupFilters = this.Ext.create("Terrasoft.FilterGroup");
                var currentPR = this.get("UsrPR");
                console.log(currentPR);
                var filterId = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "UsrPR", currentPR);
                groupFilters.addItem(filterId);
                esqDuration.filters.add(groupFilters);
                esqDuration.getEntityCollection(function(result) {
                    if (!result.success) {
                        this.showInformationDialog("Request error");
                        return;
                    } else {
                        var totalDuration = 0;
                        result.collection.each(function(item) {
                            totalDuration += item.get("UsrDurationmin");
                        });
                        this.set("totalSessionDuration", totalDuration);
                        
                        console.log(totalDuration);
                        this.showInformationDialog(totalDuration);
                         invalidMessage = this.get('Resources.Strings.DurationLimitExceeded');
                        this.showInformationDialog(invalidMessage);
                    }
                }, this);
                }
                catch(e)
                {
                    console.log(e);
                }
                finally
                {
                    return {
                        invalidMessage: invalidMessage
                    };
                }   
            }

 

 

Due to this undefined value, I am not able to check the total duration of details elements in current section record. Please guide in this regard.

Like 0

Like

1 comments

Hello,

 

From the code I can suppose that the undefined value is in the UsrPR column and it happens because the addRecord method triggers before the record values are filled in and the record is actually added (the method is triggered once the + button to add a record is clicked).

 

In case you need to get the value for the lookup column that links the detail to the main section you can use

 

this.values.DefaultValues
 

to get the value for the main section record (in the screenshot below the detail is added to the CasePage and the main entity is Case, the lookup column to connect detail to the main section in the detail is UsrCase):

Show all comments