Question

Getting this.get("columnName") as undefined when the record is opened first time

Hi,

I am trying to add an action to edit page, It should be enabled when a particular field is present. When I am opening the record from list, I am getting blank in Actions

When I reloaded it, I am able to see

 

isAddPerformanceEnabled: function(){

                var PerfFrequency = this.get("UsrPerformancefrequency");

                if(PerfFrequency){

                    return true;

                }

                

                return false;

            },

            

            addPerformancesHandler: function(){

                var concertId = this.get("Id");

                var Frequency = this.get("UsrPerformancefrequency"); 

                var serviceData = {

                    ActiveRecord: concertId,

                    Frequency: Frequency

                    

                };

                ServiceHelper.callService("CreatePerformanceDetails", "CreateDetailRecords", function(){

                    

                }, serviceData, this);

                

            },

            

            getActions: function(){

                var actionMenuItems = this.callParent(arguments);

                

                actionMenuItems.addItem(this.getButtonMenuItem({

                    Type: "Terrasoft.MenuSeparator",

                    Caption: ""

                 }));

                 

                 actionMenuItems.addItem(this.getButtonMenuItem({

                     

                     "Caption": {bindTo: "Resources.Strings.createPerformances"},

                     

                     "Tag": "addPerformancesHandler",

                     

                     "Enabled": {bindTo: "isAddPerformanceEnabled"}

              

                }));

                return actionMenuItems;

            }

 

Reason for the firstone is the particular field I am checking "UsrPerformancefrequency" is undefined when opening record from List.

Can anyone help resolve this issue?

Like 0

Like

6 comments

The issue is likely due to when you open from the list you're in combined mode, after a refresh you're in edit mode. Actions and buttons added in combined mode will get to the data from the selected row in the section list since it's technically part of the section iirc. Try this:

var freq = this.get("UsrPerformanceFrequency") || this.get("GridData").get(this.get("ActiveRow")).get("UsrPerformanceFrequency");

Ryan

Ryan Farley,

I have tried this, I am getting error at this.get("GridData")

"Cannot read property 'get' of undefined " . What I observed in debug mode is getActions() function is called before entity is initialized I can see this.isEntityInitialized= false. Until 

this.isEntityInitialized= true all the columns are having undefined value.

I have followed the same steps in academy.

I don't know how to overcome this issue. Please suggest if there is any other way, or if I am doing something wrong

Nagaraju,

Ah you're right. The getActions is called before the entity is loaded. Here's how to get around this. Instead of binding the enabled to the function, instead create a boolean virtual attribute on the page and bind enabled to that. Then, override the onEntityInitialized and set the attribute to true/false as needed. Something like this:

Add an attribute:

attributes: {
    "IsMyActionEnabled": {
        dataValueType: Terrasoft.DataValueType.BOOLEAN,
        type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
        value: false
    }
}

Now, bind the enabled of the action to this attribute:

actionMenuItems.addItem(this.getButtonMenuItem({
    "Caption": {bindTo: "Resources.Strings.createPerformances"},
    "Tag": "addPerformancesHandler",                 
     "Enabled": {bindTo: "IsMyActionEnabled"}
}));

Now, override the onEntityInitialized and set the attribute:

onEntityInitialized: function() {
    this.callParent(arguments);
    this.set("IsMyActionEnabled", !Ext.isEmpty(this.get("UsrPerformancefrequency")));
}

Ryan

Ryan Farley,

 

Hey Ryan Thanks for all your help.

Here is how I got it.

 

After trying attributes method,  Still It is working fine only after reloading.

Then I came to know that the enabling function should also present in section schema from academy. It worked after I wrote below code in section schema.

methods: {

isAddPerformanceEnabled: function(activeRowId){

                activeRowId = this.get("ActiveRow");

                var gridData = this.get("GridData");

                var selectedConcert = gridData.get(activeRowId);

                if(selectedConcert.get("UsrPerformancefrequency")){

                   return selectedConcert.get("UsrPerformancefrequency")? true   : false;

                }

}

 

But I got one question, It did not work until I added "UsrPerformancefrequency" in grid list columns. So Should I have to add all columns that I need to verify to grid or Is there a work around for this? 

Once again many thanks for helping

Nagaraju,

In the section it's possible to get only columns that are added to grid.

You can try to get the column value that is not present in the grid by selected record id via ESQ (https://academy.creatio.com/documents/technic-sdk/7-15/entityschemaquery-class-filters-handling)

Nagaraju,

In the section, add this code to make sure the column is added to the query, then it doesn't matter if the column is in the layout or not.

initQueryColumns: function(esq) {
    this.callParent(arguments);
 
    if (!esq.columns.contains("UsrPerformanceFrequency")) {
        esq.addColumn("UsrPerformanceFrequency");
    }
}

Ryan

Show all comments