Question

I am following the instructions in the academy page (https://academy.bpmonline.com/documents/technic-sdk/7-13/adding-detail-…) to create an editable list.  When I get to part 2 (Creating a Detail Schema), it says to inherit BaseGridDetailV2 base detail list schema functions, and the picture shows "Base schema - Details with list ( NUI )."  I don't see an option with the NUI in the list, but if I choose the one that is there then I get an error message "Substitution of Modules is not Allowed."  

 

These are the options I have to choose from:

 

I have looked for "BaseGrid" and "base detail list", but there are no options to choose from.  Are these instructions still up to date?

Like

2 comments

The instructions said to add a new Module, but I found that it works if I use a "Schema of the Detail View Model with List" instead.  It works fine doing it this way.

Hello Timothy,

Try to choose "Schema of the Detail View Model with List" option when adding a new module instead of "Module" options. It should help.

Best regards,
Alex

Log in or register to comment
Question

I created a module that I used to generate a custom  comboBoxEdit  view  (lookup/dropdown) , then I used that module in another page (load the component)  , and the view created successfully but without data.

To be more clear:

1- Code of my Custom Module 

define("UsrDropDownGenerator", ["ext-base", "terrasoft", "sandbox"], function (Ext, Terrasoft, sandbox) {
    Ext.define("Terrasoft.configuration.UsrDropDownGenerator", {
        alternateClassName: "Terrasoft.UsrDropDownGenerator",
        extend: "Terrasoft.BaseModule",
       
        Ext: null,
        sandbox: null,
        Terrasoft: null,
        viewModel: null,
        
        view: null,
      
        init: function () {
            debugger;
            this.callParent(arguments);
            this.initViewModel();
        },

        initViewModel: function () {
           debugger;
            var self = this;
            
            this.viewModel = Ext.create("Terrasoft.BaseViewModel", {
                values: {
                    
                    booleanValueColumnList: Ext.create("Terrasoft.Collection")
                },
                columns: {
                    
                    booleanValueColumnList: {
                        type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                        name: "booleanValueColumnList",
                        isCollection: true,
                    }
                    
                },
                methods: {

                     getColumnList: function (filters, list) {
                         
                         debugger;
                       if (list === null) {
                            return;
                        }
                        list.clear();
                        var columns = {};
                       for (var x = 0; x < 4; x++) 
                          {
                                            
                                var value1 = {
                                displayValue: "qq",
                                value:"1"
            
                              };
                            columns[x] = value1;
                          } 
            
                            list.loadAll(columns);
                            
                    },
                    
                    simpleFilterColumnChange  :function(args){
                        debugger;
                    }
                }
            });
            
        },
        
        render: function (renderTo) {
                 

 // This is executed on the module initialization, right after the init method.

            
              this.view = this.Ext.create("Terrasoft.Container", {
            
                items: [
                    Ext.create("Terrasoft.Container", {
                        renderTo: renderTo,
                    
                        items: [
                            {
                                width: "300px",
                                markerValue: "testMarker",
                                rightIconClasses: ["combobox-edit-right-icon"],
                                className: "Terrasoft.ComboBoxEdit",
                                list: {
                                    bindTo: "booleanValueColumnList"
                                },
                                prepareList: {
                                    bindTo: "getColumnList"
                                },
                                change: {
                                    bindTo: "simpleFilterColumnChange"
                                }
                                
                            }
                            
                        ]
                    })
                ]
            });
            
            
          
            this.view.bind(this.viewModel);
            
            
            return this.view;
        },

       
        destroy: function () {
            
            this.view.destroy();
           
            this.viewModel.destroy();
        }
    });
    debugger;
    
    return Terrasoft.UsrDropDownGenerator;
});
 

2- Code of my page  

......

        methods: {
                             
            onEntityInitialized:function(){
                
                this.callParent(arguments);
                
                var configObj = {
                       data : [{label : "Name" , description:"hh"},{label:"Age" , description : "10"},{label:"Job" , description : "bb"}]
                };
                                      
                this.sandbox.loadModule("UsrDropDownGenerator", {
                        renderTo: "centerPanel", //name of the container where visual module view will be displayed
                        keepAlive: true
                });
                
            },
        
            
        },

 

The dropdown was created successfully and appeared in the page  , but it does not contains any data.

When I click the dropdown ,  the getColumnList() function executed and the data are saved in the list , but no data appear in UI .

Why the data are not filled in the dropdown  , where is the problem in my code?

 

Like

1 comments

Hello,

Unfortunately, it`s hard to tell why exactly this code is not applying.

I can recommend you another, easier way to achieve it . If I understood you right, the task is to create dropdown with some values. 
To achieve it you can simply create new object that will store all the data, and add the new lookup field to the page via section wizard.

Also, you can create some custom styles for this field, more about styles can be found here: https://community.bpmonline.com/questions/how-add-custom-style-control-… and here https://community.bpmonline.com/articles/how-add-or-edit-css-style

Best regards,
Alex
 

Log in or register to comment
Question

How can I set a color value as an attribute? 

I have tried something similar to the below but it didnt work out:

attributes:{
  "labelCaption": {
		    "dataValueType": Terrasoft.DataValueType.TEXT,
		    "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
		    "value": "Test"
		   },
 
   "labelColor": {
		    "dataValueType": Terrasoft.DataValueType.COLOR,
		    "type": Terrasoft.ColorEncoding.HEX,
		    "value":"#009900"
		   }
}

Although labelCaption is working fine but labelColor is not

Like

5 comments

Hello Mohammad,

The code that you provided is working and attribute "labelColor" is storing "#009900". If this behavior is not something that you expected, please specify more accurately what are you trying to achieve.

In case you want to create some custom styles for html elements we recommend to use CSS styles instead:  https://academy.bpmonline.com/documents/technic-sdk/7-13/advanced-setti…

Best regards,
Alex

You can do this by adding a CSS module, then add this module to your page, and then specify the CSS class using the wrapClass element.

See the following for creating a CSS module:

https://community.bpmonline.com/articles/how-add-or-edit-css-style

https://community.bpmonline.com/questions/how-add-custom-style-control-…

Once you created your CSS, simply add the CSS class to the element using wrapClass. For example:

{
	"operation": "insert",
	"name": "PaymentAmount",
	"values": {
		"layout": {
		"colSpan": 12,
		"rowSpan": 1,
		"column": 0,
		"row": 1,
		"layoutName": "Tab01"
	},
	"bindTo": "PaymentAmount",
	"wrapClass": [
		"payment-amount-highlight"
	]},
	"parentName": "Tab00",
	"propertyName": "items",
	"index": 2
}

Ryan

Im trying to set the color and the text to certain values based on some conditions at runtime.. Here is the rest of the code

//In Diff
{
"operation": "insert",
"name": "HeaderLabel2",
"values": {
"itemType": 6,
	"classes": {
		"labelClass": [
			"results-caption"
		]
	},
	"layout": {
		"colSpan": 10,
		"rowSpan": 1,
		"column": 0,
		"row": 0,
		"layoutName": "Header"
		},
	"caption": {
		"bindTo": "labelcaption"
	},
	"styles": {
		"labelStyle": {
			"color":{
				"bindTo": "labelColor"
			} 
		}
	}
},
"parentName": "Header",
"propertyName": "items",
"index": 0
},
 
//In onEntityInitialized method
 
if(//some condition)
  this.set("labelColor","#ff0000");
  this.set("labelcaption", "Message Testing"));

However, as I said before, labelcaption is working fine but lableColor isnt

Mohammad Yahfoufi,

The response on this post shows you how to change the label color based on conditions: 

https://community.bpmonline.com/questions/how-add-custom-style-control-…

Ryan

Ryan Farley,

Thanks! This will work.. But why doing it as an attributes wont work?

 

Log in or register to comment
Question

I want to add borders to all dropdowns/lookups in the system.

How can I achieve that?

Like

4 comments

Dear Mohammad,

Hope you are doing well today.

If you need to change the size of the lookup fields on a page, you can do it through the section wizard. Here is the article for more details. Please refer to the paragraph 'How to set up field location on a page'

https://academy.bpmonline.com/documents/administration/7-13/how-set-pag…

Best regards,

Dean

Dear Dean Parrett,

Hope you are doing good as well.

What I wanted is to have all my dropdowns as the dropdown of the filter i.e. the field have borders and the dropdown icon is always visible. 

 

Thank you in advance!

 

Mohammad Yahfoufi,

To achieve it you simply should add your custom css styles. Here is some links that will be helpful for you.

How to add css style: 

https://community.bpmonline.com/articles/how-add-or-edit-css-style

Css style based on condition:
https://community.bpmonline.com/questions/how-add-custom-style-control-…

Advanced settings of a custom detail:
https://academy.bpmonline.com/documents/technic-sdk/7-13/advanced-setti…

Best regards,
Alex

 

Thank you Alex! 

Log in or register to comment
Question

When I click the detail row , it disappear , and a white background appear , I wonder what is the problem.

Note : I'm  working with a custom detail with list

 

Like

2 comments

this is my code

 

define("StFriendAndFamilyNumbersDetail", ["StFriendAndFamilyDetailResources", "ConfigurationGrid", "ConfigurationGridGenerator",
    "ConfigurationGridUtilities", "StServiceViewModel", "css!StServiceDetailCSS"], function (resources) {
    var detailData =[];
    var isAddMode =false;
    var isFirstTime = true;
return {
    entitySchemaName: "StFriendAndFamilyDetail",
    mixins: {
        ConfigurationGridUtilities: "Terrasoft.ConfigurationGridUtilities"
    },
    attributes: {
        "StNameFilter": {
            "dataValueType": Terrasoft.DataValueType.TEXT
        },
        "IsEditable": {
            "dataValueType": Terrasoft.DataValueType.BOOLEAN,
            "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
            "value": false
        },
        "PageNumber": {
            "dataValueType": Terrasoft.DataValueType.INTERGER,
            "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
            "value": 0
        },
        "NumberOfRecords": {
            "dataValueType": Terrasoft.DataValueType.INTERGER,
            "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
            "value": 15
        }
    },
    methods: {
        sortColumn: this.Terrasoft.emptyFn,
        loadGridData: this.Terrasoft.emptyFn,
        loadFilter: function () {
            this.set("PageNumber", 0);
            var gridData = this.getGridData();
            if (gridData) {
                gridData.clear();
                this.set("IsDetailCollapsed", false);
                this.loadSearchItems(
                    this.get("StNameFilter"),
                    this.get("PageNumber"),
                    this.get("NumberOfRecords"),
                    gridData
                );
            }
        },
        loadMore: function () {
            var pageNumber = this.get("PageNumber");
            this.set("PageNumber", ++pageNumber);
            var gridData = this.getGridData();
            if (gridData) {
                this.loadSearchItems(
                    this.get("StNameFilter"),
                    this.get("PageNumber"),
                    this.get("NumberOfRecords"),
                    gridData
                );
            }
        },
        generateActiveRowControlsConfig: function (id, columnsConfig, rowConfig) {
            debugger;
            this.columnsConfig = columnsConfig;
            var gridLayoutItems = [];
            var currentColumnIndex = 0;
            this.Terrasoft.each(columnsConfig, function (columnConfig) {
                var columnName = columnConfig.key[0].name.bindTo;
                var column = this.getColumnByColumnName(columnName);
                var cellConfig = this.getCellControlsConfig(column);
                cellConfig = this.Ext.apply({
                    layout: {
                        colSpan: columnConfig.cols,
                        column: currentColumnIndex,
                        row: 0,
                        rowSpan: 1
                    }
                }, cellConfig);
            /*    if (cellConfig.name === "StServiceParams") {
                    this.set("ComboBoxCollection", new this.Terrasoft.Collection());
                    cellConfig.contentType = Terrasoft.ContentType.ENUM;
                    cellConfig = this.Ext.apply({
                        controlConfig: {
                            list: {
                                bindTo: "ComboBoxCollection"
                            },
                            prepareList: {
                                bindTo: "getComboBoxItems"
                            },
                            change: {
                                bindTo: "ontServiceParamsChange"
                            }
                        }
                    }, cellConfig);
                    cellConfig.enabled = true;
                }
                else {
                    cellConfig.enabled = false;
                }*/
                gridLayoutItems.push(cellConfig);
                currentColumnIndex += columnConfig.cols;
            }, this);
            var gridData = this.getGridData();
            var activeRow = gridData.get(id);
            var options = activeRow.values;
            activeRow.setOptions(options);
            var viewGenerator = this.Ext.create("Terrasoft.ViewGenerator");
            viewGenerator.viewModelClass = { prototype: this };
            var gridLayoutConfig = viewGenerator.generateGridLayout({
                name: this.name,
                items: gridLayoutItems
            });
            console.log(gridLayoutConfig);
            rowConfig.push(gridLayoutConfig);
        },
    
    /*    onSubmitDetail: function () {
            var selectedRows = this.get("SelectedRows");
            if (selectedRows && selectedRows.length > 0) {
                for (var i = 0; i < selectedRows.length; i++) {
                    var selectedItem = this.getGridData().collection.getByKey(selectedRows[i]);
                }
                debugger;
                // TODO selected items processing logic
            }
            else {
                this.showInformationDialog("There isn't any selected item");
            }
        },*/
        init: function (callback, scope) {
            this.set("PageNumber", 0);
            this.callParent([
                function () {
                    var gridData = this.getGridData();
                    if (gridData) {
                        gridData.clear();
                        this.set("IsDetailCollapsed", false);
                        this.loadSearchItems( null, this.get("PageNumber"),
                        this.get("NumberOfRecords"), gridData);
                    }
                    callback.call(scope);
                }, this
            ]);
        
        
            this.sandbox.subscribe("SendDetailData", function (arg) {
                    debugger;
                     detailData = arg.array;

                    this.UpdateRatePlanServices();

                }, this, ["SendDetailDataKey"]);
                
                
            this.sandbox.subscribe("GetDetailData", function (arg) {
                   debugger;
                   var gridData = this.getGridData();
                   var array=[];
        
                if(isFirstTime){
                    
                    isFirstTime=false;
                    
                    for (var i = 0; i < gridData.collection.items.length; i++) {
                           
                           var item = gridData.collection.items[i];
                           var obj={};
                        obj.Id = item.values.StId;
                        obj.PhoneNumber = item.values.StPhoneNumber;
                        obj.ContractId = item.values.StContractId;
                        
                        array.push(obj);
                           
                       }
                       
                    return array;
                    
                }else{
                    
                    return detailData;
                    
                }
                   
                    
           }, this, ["GetDetailDataKey"]);
        
        
        },
        onDetailCollapsedChanged: function () {
            this.callParent(arguments);
            if (!this.get("IsDetailCollapsed")) {
                this.set("PageNumber", 0);
                var gridData = this.getGridData();
                if (gridData) {
                    gridData.clear();
                    this.loadSearchItems( null, this.get("PageNumber"),
                    this.get("NumberOfRecords"), gridData);
                }
            }
        },
        loadSearchItems: function (nameFltr, pageNb, nbOfRecords, gridData) {
    
            debugger;

            var contractId = this.sandbox.publish("GetContractIDMessage", null, ["GetContractIDMessageKey"]);
            
            this.set("MaskId", Terrasoft.Mask.show({ timeout: 0 }));
            this.set("IsGridEmpty", true);
            this.set("IsGridLoading", true);
            this.set("IsGridDataLoaded", false);
            
            if(detailData == null || detailData == "" || detailData == []){
                
                var serviceConfig = {
                    serviceName: "StContractManagerService",
                    methodName: "GetFriendAndFamilyNumbers",
                    timeout: 120000,
                    data: { 
                        contractId: contractId
                    }
                };
                isAddMode = false;
            }else{
                
                var serviceConfig = {
                    serviceName: "StContractManagerService",
                    methodName: "ConstructFriendAndFamilyDetail",
                    timeout: 120000,
                    data: { 
                        array: JSON.stringify(detailData)
                    }
                };
                    isAddMode = true;
            }
            
            this.callService(serviceConfig, function (responseJson) {
                this.set("IsGridLoading", false);
                this.set("IsGridDataLoaded", true);
                if (!this.Ext.isEmpty(responseJson)) {
                    
                        if(!isAddMode){ 
                            var response = this.Ext.decode(responseJson.GetFriendAndFamilyNumbersResult);
                        }else{
                            var response = this.Ext.decode(responseJson.ConstructFriendAndFamilyDetailResult);
                        }
                        
                    if (response.success) {
                            console.log(response);
                        if (response.rowsAffected > 0) {
                            this.set("IsGridEmpty", false);
                            this.set("CanLoadMoreData", response.canShowMore);
                            var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
                                rootSchemaName: "StFriendAndFamilyDetail",
                                rowViewModelClassName: "Terrasoft.StServiceViewModel"
                            });
                            esq.parseResponse(response, function (result) {
                                if (result.success) {
                                    console.log(result);
                                    var resultCollection = result.collection;
                                    resultCollection.each(function (item) {
                                    item.init(this);
                                    }, this);
                                    gridData.loadAll(result.collection);
                                    this.prepareResponseCollection(resultCollection);
                                    Terrasoft.Mask.hide(this.get("MaskId"));
                                    
                                    
                                }
                                else {
                                    this.showInformationDialog(result.errorInfo);
                                    Terrasoft.Mask.hide(this.get("MaskId"));
                                }
                            }, this);
                        }
                        else {
                            this.set("CanLoadMoreData", false);
                            Terrasoft.Mask.hide(this.get("MaskId"));
                        }
                    }
                    else {
                        this.set("CanLoadMoreData", false);
                        this.showInformationDialog(response.errorInfo.message);
                        Terrasoft.Mask.hide(this.get("MaskId"));
                    }
                }
            }, this);
        },
    
        UpdateRatePlanServices: function(){
            var gridData = this.getGridData();
                    if (gridData) {
                        gridData.clear();
                        this.set("IsDetailCollapsed", false);
                        this.loadSearchItems( null, this.get("PageNumber"),
                        this.get("NumberOfRecords"), gridData);
                    }
            },
    
        
        onActiveRowAction: function (buttonTag,primaryColumnValue) {
                debugger;
                switch (buttonTag) {
                case "someButton":
                //this.onSomeButtonClicked(primaryColumnValue);
                break;
                default:
                break;
                }
        },
                
    },
    messages: {
            "SendDetailData": {
                mode: Terrasoft.MessageMode.PTP,
                direction: Terrasoft.MessageDirectionType.SUBSCRIBE
            },
             "GetDetailData":
             {
                mode: Terrasoft.MessageMode.PTP,
                direction: Terrasoft.MessageDirectionType.SUBSCRIBE
            },
            "GetContractIDMessage": {
                mode: Terrasoft.MessageMode.PTP,
                direction: Terrasoft.MessageDirectionType.PUBLISH
            },

        },
    diff: /**SCHEMA_DIFF*/[
        {
            "operation": "merge",
            "name": "DataGrid",
            "parentName": "Detail",
            "values": {
                "className": "Terrasoft.ConfigurationGrid",
            //    "generator": "ConfigurationGridGenerator.generatePartial",
                "generateControlsConfig": { "bindTo": "generateActiveRowControlsConfig" },
                /*"changeRow": { "bindTo": "changeRow" },*/
                "multiSelect": true
            },
            "index": 0
        },

    {
                "operation": "merge",
                "name": "DataGrid",
                "values": {
                    "activeRowAction": {"bindTo": "onActiveRowAction"},
                    "activeRowActions": []
                    
                }
            },
            {
                "operation": "insert",
                "name": "DataGridActiveRowSomeButton",
                "parentName": "DataGrid",
                "propertyName": "activeRowActions",
                "values": {
                    "className": "Terrasoft.Button",
                    "style": Terrasoft.controls.ButtonEnums.style.GREEN,
                    "caption": "Details",
                    "tag": "someButton"
                }
            },
    
            
    
    ]
    /**SCHEMA_DIFF*/
};
});
 

Hello Mohamad!

To resolve this problem you should debug js client code. Here you can read additional information about debugging client code:
https://academy.bpmonline.com/documents/technic-sdk/7-13/client-code-de… 

If I got this right, method "generateActiveRowControlsConfig" triggers when user clicks on row, so you should pay an extra attention to it.

Best regards,
Alex

Log in or register to comment
Question

Hello,

I created a custom virtual detail and I fill it with data , I have column called 'url' and I want to make its value linkable .

Like

2 comments

I made my text controls on the Edit page of a record clickable hyperlinks with the help of this question https://community.bpmonline.com/articles/creating-custom-web-link-field

Log in or register to comment
Question

Hi,

I developed a package that name is 'A', which I try to import on another instance of bpm'online .In new instance current Package id is set 'A'. if  any changes made gets reflected in the custom package (default) not in the new package.

 

Please give me your feedback..

Regards,

Sunitha

Like

3 comments

Dear Sunitha,

Please check if your package is locked or unlocked (it will be gray if it is locked). Packages are usually locked if they were imported to another instance. 

currently import package is lock.how to unlock my package using new instance

 

Sunithaa.s,

They are locked because development process expects user to develop everything on dev- and then transfer changes to prod. They are locked because system expects they are finished and will not be changed anymore. You can read more about developing process on our Academy: https://academy.bpmonline.com/documents/technic-sdk/7-13/how-start-deve…

If this way is not suitable for you you can use version control to transfer the changes and be able to modify them later (see https://academy.bpmonline.com/documents/technic-sdk/7-13/transferring-c… for more information) 

Log in or register to comment
Question

I use the OData to extract the data. I need to get cases with the specific status from the CaseCollection. To do this I use the following Http-request:

https://company.bpmonline.com/0/ServiceModel/EntityDataService.svc/Case… eq guid'7e9f1204-f46b-1410-fb9a-0050ba5d6c38'.

But I recieve the "404 ERROR

<code>1</code>

<messagexml:lang="">Элемент коллекции с именем StatusId не найден</message> " (The element  StatusId is not found").

But if I do https://ticketland.bpmonline.com/0/ServiceModel/EntityDataService.svc/C… 
it responses with 200 OK.

How to retrieve cases with the specific StatusId from CaseCollection? 

Like

1 comments

Hello Timur,

The Status column in the Case table is the foreign key for CaseStatus table. Therefore, the correct syntax is the next: [Name_of_joinable_table / Name_of_column_for_linking_of_joinable_table].
In your example it will be: https://ticketland.bpmonline.com/0/ServiceModel/EntityDataService.svc/C… eq guid'7e9f1204-f46b-1410-fb9a-0050ba5d6c38'.

Log in or register to comment
Question

Hello Community, 

I was wondering if anyone has come across this request: 

 

A client would like to have multiple details that they can interact with and then one master detail showing all of the subsequent details and their records. 

 

Example 

Detail 1 has records: A, B and C

Detail 2 has records 1, 2 and 3

Detail 3 would have A, B, C, 1, 2 and 3 

Like

1 comments

Dear Philip,

To accomplish the task you need to go through the following steps:

1. Create a view in the database.

2. Create the object in bpm'online linked to the view. Please note that the set of columns in the system should be the same as in the database view.

3. Link your custom detail to the object from p.2. 

Lisa

Log in or register to comment
Question

Hi,

I'm working on some development and came across this question. Please find below:

"When processing an order, check if the total amount of overdue payments/invoices exceeds $4,000. If it exceeds $4,000 then display this message: "Overdue payments/invoices = $X 100% advance payment required" and do not allow to save changes."
I understand that what needs to be possibly done is to over-ride the the save method, but I'm unable to find this in order to proceed further. I'm unable to find anything related to this in the development guide. Could you possibly help me out as to how to proceed?

Regards,

Sushanth.

Like

5 comments

Dear Sushanth,

 

To fulfill such task you need to override the save method. This should look like this:

save: function() {
		//get the value of columns and check if number exceeds the limit
		var payments = this.get("Payments");
		var invoices = this.get("Invoices");
		//do the calculation
		var overdue = payments/invoices;
		if (overdue >= 4000) {
			this.showInformationDialog("Overdue payments/invoices = $X 100% advance payment required");
			return;
		} else {
		//if less then 4000, we proceed with save
			this.callParent(arguments);
		}
	}

 

 

Hope this will help.

 

Regards,

Anastasia

Hi Anastasia,
Thank you for that. I've worked ahead from there. Now I'm just stuck with regard to the query. I understand that one of my filters is hitting an error. Attaching my code (InvoicePageV2) with comments followed by my issue.

save: function() {
				var select = this.Ext.create("Terrasoft.EntitySchemaQuery", {
						rootSchemaName: "Invoice"
					});
				var contactid = this.get("Contact"); // I'm trying to retrieve the contact the invoice is associated with. 
				var amount = this.get("Amount");
				var paymentAmount = this.get("PaymentAmount");
				select.addAggregationSchemaColumn("Amount", Terrasoft.AggregationType.SUM, "TotalAmount");
				select.addAggregationSchemaColumn("PaymentAmount", Terrasoft.AggregationType.SUM, "TotalPaymentAmount");
                                //this filter seems to be the issue.
				var esqFirstFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Contact", contactid);
				var esqSecondFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.NOT_EQUAL, "PaymentStatus", "3fb932ea-f36b-1410-2691-00155d043205");
				select.filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
				select.filters.add("esqFirstFilter", esqFirstFilter);
				select.filters.add("esqSecondFilter", esqSecondFilter);
				select.getEntityCollection(function(response) {
						if (response.success) {
							var totalAmount = response.collection.getByIndex(0).get("TotalAmount") + amount;
							var totalPaymentAmount = response.collection.getByIndex(0).get("TotalPaymentAmount") + paymentAmount;
							var totalDue = totalAmount - totalPaymentAmount;
							if (totalDue > 4000) {
								this.showInformationDialog("Payment Overdue");
								return;
							}
							else {
								this.callParent(arguments);
							}
						} else {
							this.showInformationDialog("ESQ Error");
						}
					}, this);
			}

So is my retrieval of the contact associated with the invoice wrong? or am i going wrong somewhere else. Looking forward to hearing from you.

Regards,
Sushanth

Dear Sushanth,

You are correct rearding the filter causing the issue. It was not working, because you were passing the whole object to the filter, but not just Id. To overcome this, modify the way you retrieve contact var contactid =this.get("Contact").Id;

Also, please draw your attention to the fact, that ESQ is an asynchronious function and Save() is synchronious. Therefore, better to do the calculation prior save method, e.g. when contact is changed and set the value to some attribute, which can be accessed in save method.

Regards,

Anastasia

Hi Anastasia,
I've made the requirement work with some issues. Still testing it further but I want some review on if there is better way to do this. Find my code below:

				validateAccountOrContactFilling: function(callback, scope) {
					var account = this.get("Account");
					var contact = this.get("Contact");
					var result = {
						success: true
					};
					var select = this.Ext.create("Terrasoft.EntitySchemaQuery", {
						rootSchemaName: "Invoice"
					});
					var amount = this.get("Amount");
					if (amount === undefined) {
						amount = 0;
					}
					var paymentAmount = this.get("PaymentAmount");
					if (paymentAmount === undefined) {
						paymentAmount = 0;
					}
					select.addAggregationSchemaColumn("Amount", Terrasoft.AggregationType.SUM, "TotalAmount");
					select.addAggregationSchemaColumn("PaymentAmount", Terrasoft.AggregationType.SUM, "TotalPaymentAmount");
					var esqSecondFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.NOT_EQUAL,
							"PaymentStatus", "3fb932ea-f36b-1410-2691-00155d043205");
					var esqThirdFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.LESS, "DueDate", new Date());
					select.filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
					if (contact) {
						var esqFirstFilterContact = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
								"Contact", contact.value);
						select.filters.add("esqFirstFilterContact", esqFirstFilterContact);
					}
					else {
						var esqFirstFilterAccount = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
								"Account", account.value);
						select.filters.add("esqFirstFilterAccount", esqFirstFilterAccount);
					}
					select.filters.add("esqSecondFilter", esqSecondFilter);
					select.filters.add("esqThirdFilter", esqThirdFilter);
					select.getEntityCollection(function(response) {
							if (response.success) {
								var totalAmount = response.collection.getByIndex(0).get("TotalAmount") + amount;
								var totalPaymentAmount = response.collection.getByIndex(0).get("TotalPaymentAmount") + paymentAmount;
								var totalDue = totalAmount - totalPaymentAmount;
								if (totalDue > 4000) {
									this.showInformationDialog("Overdue payments/invoices = $" + totalDue + " 100% advance payment required");
									result.success = false;
									callback.call(scope || this, result);
								}//issue in this else bock.
								else {
									this.save();
									callback.call(scope || this, result);
								}
							} else {
								this.showInformationDialog("ESQ Error");
							}
						}, this);
				}

So when creating a new invoice, this script works perfectly - validation for due amount, validation for contact/account field and saving only when the due amount is less that 4000$. But when I modify the payment amount such that the due amount is less than 4000$, the callback function is causing a loop. I've tried replacing the callback with return, but it however doesn't work! Could you please suggest? Also, I did try overriding the save function, but that gave me other issues, so decided to replace this function!
Regards,
Sushanth.

Hi,
Alright. Debugged it and found out the issue. The save function I called - this.save() triggered a loop. I've fixed it now. Works well! Attaching my code.

validateAccountOrContactFilling: function(callback, scope) {
	var account = this.get("Account");
	var contact = this.get("Contact");
	var result = {
		success: true
	};
	var select = this.Ext.create("Terrasoft.EntitySchemaQuery", {
		rootSchemaName: "Invoice"
	});
	var amount = this.get("Amount");
	if (amount === undefined) {
		amount = 0;
	}
	var paymentAmount = this.get("PaymentAmount");
	if (paymentAmount === undefined) {
		paymentAmount = 0;
	}
	select.addAggregationSchemaColumn("Amount", Terrasoft.AggregationType.SUM, "TotalAmount");
	select.addAggregationSchemaColumn("PaymentAmount", Terrasoft.AggregationType.SUM, "TotalPaymentAmount");
	var esqSecondFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.NOT_EQUAL,
			"PaymentStatus", "3fb932ea-f36b-1410-2691-00155d043205");
	var esqThirdFilter = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.LESS, "DueDate", new Date());
	select.filters.logicalOperation = Terrasoft.LogicalOperatorType.AND;
	if (contact) {
		var esqFirstFilterContact = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
				"Contact", contact.value);
		select.filters.add("esqFirstFilterContact", esqFirstFilterContact);
	}
	else {
		var esqFirstFilterAccount = select.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
				"Account", account.value);
		select.filters.add("esqFirstFilterAccount", esqFirstFilterAccount);
	}
	select.filters.add("esqSecondFilter", esqSecondFilter);
	select.filters.add("esqThirdFilter", esqThirdFilter);
	select.getEntityCollection(function(response) {
			if (response.success) {
				var totalAmount = response.collection.getByIndex(0).get("TotalAmount") + amount;
				var totalPaymentAmount = response.collection.getByIndex(0).get("TotalPaymentAmount") + paymentAmount;
				var totalDue = totalAmount - totalPaymentAmount;
				if (totalDue > 4000) {
					this.showInformationDialog("Overdue payments/invoices = $" + totalDue + " 100% advance payment required");
					result.success = false;
					callback.call(scope || this, result);
				}
				else {
					result.success = true;
					callback.call(scope || this, result);
				}
			} else {
				this.showInformationDialog("ESQ Error");
			}
		}, this);
}

Just let me know if there are any improvements you'd suggest.
Regards,

Sushanth.

Log in or register to comment