We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

ActionComplete event not firing properly

Thread ID:

Created:

Updated:

Platform:

Replies:

119415 Jun 17,2015 08:34 AM Jun 23,2015 09:38 AM ASP.NET MVC 5
loading
Tags: Gantt
Pankaj Chatterjee
Asked On June 17, 2015 08:34 AM

The script for the ActionComplete event is given below. It is based on the discussion on How to save data to SQL thread and the scripts provided by SyncFusion.

Problem noted is as follows -
1. When I press "Save" button in the Add Task dialog, the ActionComplete event is fired twice. The first time the event is fired, the "args.requestType" equals   "recordUpdate" with the values in the dialog box. Subsequently the ActionComplete is fired again with requestType being "save". However, this time, the args._cAddedRecord has only null values. 

Am I doing something wrong here?

regards
Pankaj


--------------------

    function ActionComplete(args) {

        debugger;

        //alert("here " + args.requestType +" Add? " + args._cAddedRecord  +"   :: Mod?" + args._cModifiedData);

        var ganttRecord = args.data;

        if (args.requestType === 'save' || args._cAddedRecord) {

            //Newly Added Record is obtained here , which can be updated to database

            if (args._cAddedRecord.parentItem)

                ganttRecord["ParentId"] = args._cAddedRecord.parentItem.taskId;

            $.ajax({

                type: "POST",

                url: "/Plan/Add",//Add is Server side method

                data: ganttRecord,

                dataType: "json"


            });


        } else if (args.requestType === 'save' && args._cModifiedData) {

            //Edited Record is obtained here , which can be updated to database

            if (args._cModifiedData.parentItem)

                ganttRecord["ParentId"] = args._cModifiedData.parentItem.taskId;

            ganttRecord["Predecessor"] = args._cModifiedData.item.Predecessor;


            $.ajax({

                type: "POST",

                url: "/Plan/Update"//Update is Server side method

                data: ganttRecord,

                dataType: "json"

            });

        } else if (args.requestType === 'delete') {

            var ganttRec = args.data.item;

            $.ajax({

                type: "POST",

                url: "/Plan/Delete"//Update is Server side method

                data: ganttRec,

                dataType: "json"

            });


            if (data.hasChildRecords) {

                deleteChildRecords(data);

            }


        }

            // To update the database during Outdent,editing,indent,predecessor update operation

        else if (args.requestType === 'outdent' || args.requestType === 'recordUpdate') {

            //alert("3");

            var ganttRec = args.data.item;

            $.ajax({

                type: "POST",

                url: "/Plan/Update"//Update is Server side method

                data: ganttRec,

                dataType: "json"

            });

        }


    }


--------------------

Mahalakshmi Karthikeyan [Syncfusion]
Replied On June 18, 2015 09:35 AM

Hi Pankaj,

For your kind information.

Query 1: When I press "Save" button in the Add Task dialog, the ActionComplete event is fired twice.

Solution:  We are not able to reproduce the reported issue while adding a task. ActionComplete will fire for multiple times while we adding a new task, is because while we adding a new task we have to update its depended task if there is any date changes. But args.requestType==”save” will fire only once and that time we can get the args._cAddeRecord with the newly entered details. Please ensure that you are using updated script from our dashboard. If you still facing any issue please revert to us by modifying the attached sample along with replication the replication procedure.

Query 2: Subsequently the ActionComplete is fired again with requestType being "save". However, this time, the args._cAddedRecord has only null values. 

Solution: We are not able to reproduce the issue with args.requestType ==”save” and we are getting the appropriate new record details in the args._cAddedRecord. We have also analyzed your code provided in your last update and came to know that there is some code missing to add a new record to database. Please refer the below code snippet for details.

function ActionComplete(args) {           


            //alert("here " + args.requestType +" Add? " + args._cAddedRecord  +"   :: Mod?" + args._cModifiedData);


            if (args.requestType === 'save' || args._cAddedRecord) {

                debugger;

                //Newly Added Record is obtained here , which can be updated to database

                var ganttRecord = args._cAddedRecord.item;

                if (args._cAddedRecord.parentItem)


                    ganttRecord["ParentId"] = args._cAddedRecord.parentItem.taskId;


                $.ajax({


                    type: "POST",


                    url: "/Plan/Add",//Add is Server side method


                    data: ganttRecord,


                    dataType: "json"


                });

            }

}


We have also prepared a sample based on this and you can find the sample under the following location.

Sample: http://www.syncfusion.com/downloads/support/forum/119415/ze/MVC5Gantt1507325683

Please let us know if you need further assistance on this.

Regards,

Mahalakshmi K.


Pankaj Chatterjee
Replied On June 20, 2015 02:43 AM

Mahalaxmi,

I do not think I was able to explain properly, so here goes......

Almost all examples given as sample are working on in memory model. Then in the thread ID#117764,  you had posted an sample for storing the data in the database. The sample had the following code in the ActionComplete event

            if (args.requestType === 'save' && args._cAddedRecord) {
                //Newly Added Record is obtained here , which can be updated to database

            } else if (args.requestType === 'save') {
                //Edited Record is obtained here , which can be updated to database
            }
            else if (args.requestType === 'delete') {
                //Delete logic
            }

With this code, I was facing an issue that any indent, outdent or modification performed on the ChartView pane was not firing the ActionComplete event. To this your response was the following code 

            if (args.requestType === 'save' && args._cAddedRecord) {
                //Newly Added Record is obtained here , which can be updated to database
                var ganttRecord = args._cAddedRecord.item;
            }
            else if (args.requestType === 'delete') {
                var data =args.data;
                var ganttRec = data.item;
            }
            // To update the database during Outdent,editing,indent,predecessor update operation
            else if (args.requestType === 'outdent' || args.requestType === 'recordUpdate') {               
                var ganttRec = args.data.item;
            }           

--------------
Now the issue.

The ActionComplete event is being fired twice (and as you say, it will be fired multiple times). Now consider, that I add a record. The first requestType is "recordUpdate" which in turn fires a call to the Update action of the controller, then the next time requestType is set as "save" and then a call can be made to the "Save' action of the controller.

There is no state information available, in the data available on the server, so when the call is made to the Update (1st call during add), there is no way to determine whether the call is actually a Add or Update.  So the only option for me is to check whether the data exists in the database. In that case, I do not find the need for the "save" requestType

 


Mahalakshmi Karthikeyan [Syncfusion]
Replied On June 22, 2015 09:48 AM

Hi Pankaj,

Sorry for the inconvenience caused.

For your kind information, the args.requestType==”recordUpdate” will fire for the each number of parents that particular affected task contains. For example if we add a new task, which is having 3 parent tasks as like in the below screen shot,


In this case if we select “child task 1” and press add button and save the task, actionComplete will fired for 6 times is to perform the different actions as like in the below table.


Event

Request type

Number of calls

Purpose

ActionComplete

args.requestType==”refresh”

1

to refresh the Gantt to update the view for new item added,

args.requestType==”recordUpdate”

4

to update its immediate parent items for the changes, and to update the same item for any predecessor changes.

args.requestType==”save”

1

For this specific argument type alone, the args._cAddedRecord argument will be generated with the newly added task details. The remaining event trigger this argument will not be available


Same as while we editing also args.requestType==”recordUpdate” will fired for the number of parents it contains. And at the time of args.requestType==”save” it will get the args._cModifiedRecord with the modified details.

We would also like to inform you that we have also logged feature report on to “Optimizing client side events in Gantt” for implementing single batch update for various triggered events in near future. It will be available in any our upcoming main release.

Regards,

Mahalakshmi K.


Pankaj Chatterjee
Replied On June 22, 2015 12:38 PM

Dear Mahalaxmi,

I am not getting the behaviour as mentioned in your mail.

Let us say that there is only one task entry (or a blank chart). I select the last entry and click on the "+" sign or right click and say "add task below". A window pops up. I fill up the record, then press "Save".

Now the behaviour I am getting is that ActionComplete will fire twice. The  First time the requestType is "updateRecord" with all the items of the newly added record. Second time around "Save" is fired with all the items of the newly added record. 

There is no problem, if the ActionComplete fires multiple times. The issue is at the server side, how do I ignore the "updateRecord" event fired during the Add for the newly added record prior to "save" requstType?

regards
Pankaj

Mahalakshmi Karthikeyan [Syncfusion]
Replied On June 23, 2015 09:38 AM

Hi Pankaj,

Sorry for the inconveniance caused.

We can also reproduce the reported scenario. While we add a new record, in the case you reported, first requestType will be “argrs.requestType==recordUpdate” and the second call is for “argrs.requestType==save” in client side, but we pass the request through the ajax post, in the server side  the process is reversed where the Add() method is called priorly to the Update() method when adding a new record , and it will not create any problem while we adding a record to the SQL server database. But still we are analysing on why the args.requestType==”recordUpate” triggers prior to the args.requestType==”save” in the client side for ActionComplete event. We will let you know the status in one business day(24/06/2015).

Regards,

Mahalakshmi K.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;