Hello!

 

I am trying to get the date field updated for multiple records using a custom Action.

I have referred to this article for it: Change of the field value of multiple records using custom action | Community Creatio

 

I have successfully created a pop up but, the update is not reflecting in the selected records.

I have also attached the screenshot of it and the code that I have used.

 

The code that I have used:

 



                getSectionActions: function() {

                  actionMenuItems.addItem(this.getButtonMenuItem({

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

                        "Click": {bindTo: "showDateInfo"},

                        "Enabled": {bindTo: "isCustomActionEnabled"}

                    }));

                    // Returning of the added section action collection.

                    return actionMenuItems;

                },

             

              showDateInfo: function() {

                Terrasoft.utils.inputBox("Set Visit Date for update", function(result, arg) {

                        if (result === Terrasoft.MessageBoxButtons.YES.returnCode) {

                            var date = arg.date.value;

                         

                            var autoIds = this.getSelectedItems();

                            this.updateDate(function(context, result) {

                            }, autoIds, date);

 

                        }

                    }, [{

                        className: "Terrasoft.Button",

                        caption: "OK",

                        returnCode: "yes"

                    }, "cancel"], this,

                    {

               

                        date: {

                            dataValueType: Terrasoft.DataValueType.DATE,

                            caption: "Visit Date",

                            customConfig: {

                                className: "Terrasoft.DateEdit",

                                height: "17px"

                            }

                       

                    },          

                    },

                                         

                    {

                        defaultButton: 0,

                        style:  {

                            borderStyle: "ts-messagebox-border-style-blue ts-messagebox-border-no-header",

                            buttonStyle: "blue"

                        }

                    }

                );

            },

              updateDate: function(callback, autoIds, date) {

                        var update = Ext.create("Terrasoft.UpdateQuery", {

                            rootSchemaName: "JFLFieldSales"

                        });

                        var filters = Terrasoft.createFilterGroup();

                        filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;

                        autoIds.forEach(function(item) {

                            var productIdFilter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,

                            "Id", item);

                            filters.add("ProductIdFilter" + item, productIdFilter);

                        }, this);

                        update.filters.add(filters);

                        if (date) {

                            update.setParameterValue("JFLAssignmentDate", date, Terrasoft.DataValueType.Date);

                        //  update.setParameterValue("JFLAssignmentDate", time, Terrasoft.DataValueType.Date);

                        }

                        

                        update.execute(function(result) {

                            callback.call(this, result);

                        }, this);

              }

            }

        };

    });

 

 

 

I have also attached full code of the schema as a file.

 

Also, please let me know if I can update the time also as the field in the record is of type DATE_TIME.

File attachments
Like 0

Like

1 comments

Hello Malay,

 

To update the date a little customization is needed. Here is an example of my update function:

updateAccount: function(callback, autoIds, valueWarranty, valueDelivery, valueDate) {
                        var update = Ext.create("Terrasoft.UpdateQuery", {
                            rootSchemaName: "Account"
                        });
                        var filters = Terrasoft.createFilterGroup();
                        filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                        autoIds.forEach(function(item) {
                            var accountFIlter = update.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL,
                            "Id", item);
                            filters.add("ProductIdFilter" + item, accountFIlter);
                        }, this);
                        update.filters.add(filters);
                        if (valueWarranty) {
                            update.setParameterValue("UsrWaranty", valueWarranty, Terrasoft.DataValueType.TEXT);
                        }
                        if (valueDelivery) {
                            update.setParameterValue("UsrDelivery", valueDelivery, Terrasoft.DataValueType.TEXT);
                        }
            			if (valueDate) {
                          	valueDate="\""+valueDate+"T00:00:00.000"+"\"";
                            update.setParameterValue("UsrDate", valueDate, Terrasoft.DataValueType.DATE);
                        }
                        update.execute(function(result) {
                            callback.call(this, result);
                        }, this);
                    }

The main idea here is in this string:

valueDate="\""+valueDate+"T00:00:00.000"+"\"";

 

If you take a look at the regular update query that is sent when manually changing the date column value you will see that the value is transferred as "2021-03-21T00:00:00.000". To successfully update the date column using the modal window you will need to pass the date value as: 2021-03-21 and then the function itself will transform the value to "2021-03-21T00:00:00.000", add it to the update query parameters and send it to the server. As a result the field will be updated.

 

Best regards,

Oscar

Show all comments