field being updated when no changes

field being updated when no changes

montoyammontoyam Posts: 568Questions: 136Answers: 5

I am trying to submit only when actual changes are made and for some reason, I have a field, FollowUpDate, that when it is blank it says it is being updated, even though it is even hidden in the Editor and there is nothing special going on in the Controller. When FollowUpDate field has a value, it does not trigger an update (when no other things are changed on submit):

    var BillingEditor = new $.fn.dataTable.Editor({
        ajax: 'api/Billing',
        table: '#BillingSummary',
        formOptions: {
            main: {
                submit: 'changed' //allIfChanged 
            }
        },
        fields: [
            { name: "CaseNumber", label: "Case Number", type: "readonly" },
            { name: "ActionName", label: "Action", type: "readonly" },
            { name: "DefendantName", label: "Defendant", type: "readonly" },
            { name: "StandardBillingRate", label: "Standard Billing Rate", type: "readonly" },
            {
                name: "BilledDate",
                label: "Date Billed",
                type: "datetime",
                format: 'MM-DD-YYYY'
            },
            { name: "BillingAmount", label: "Amount Billed" },
            { name: "CaseID", label: "CaseID", type: "hidden" },
            { name: "ActionID", label: "ActionID", type: "hidden" },
            { name: "CaseDefendantID", label: "CaseDefendantID", type: "hidden" },
            { name: "ActionDate", label: "ActionDate", type: "hidden" },
            { name: "FollowUpDate", label: "FollowUpDate", type: "hidden" },
            { name: "ActionStatusID", label: "ActionStatusID", type: "hidden" },
            { name: "FollowUpStaffID", label: "FollowUpStaffID", type: "hidden" },
            { name: "ActionNote", label: "ActionNote", type: "hidden" },
            { name: "CompletedDate", label: "CompletedDate", type: "hidden" },
            { name: "EnteredBy", label: "EnteredBy", type: "hidden" }
        ]
    });
    public class BillingController : ApiController
    {
        [Route("api/Billing")]
        [HttpGet]
        [HttpPost]
        public IHttpActionResult Billing()
        {
            var request = HttpContext.Current.Request;
            var settings = Properties.Settings.Default;

            using (var db = new Database(settings.DbType, settings.DbConnection))
            {
                var response = new Editor(db, "vw_BillingInfo", "CaseActionID")
                    .Field(new Field("CaseID").Set(false))
                    .Field(new Field("CaseNumber").Set(false))
                    .Field(new Field("CompletedDate").GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy")).Set(false))
                    .Field(new Field("DefendantName").Set(false))
                    .Field(new Field("ClientName").Set(false))
                    .Field(new Field("ActionName").Set(false))
                    .Field(new Field("StandardBillingRate").Set(false))
                    .Field(new Field("StatusName").Set(false))
                    .Field(new Field("ActionCompleted").Set(false))
                    .Field(new Field("ActionDate").GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy")).Set(false))
                    .Field(new Field("BillingAmount"))
                    .Field(new Field("BilledDate").GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy")).SetFormatter(Format.NullEmpty()))
                    .Field(new Field("BillingStatus").Set(false))
                    .Field(new Field("CaseDefendantID").Set(false))
                    .Field(new Field("ActionID").Set(false))
                    .Field(new Field("FollowUpDate").Set(false))
                    .Field(new Field("ActionStatusID").Set(false))
                    .Field(new Field("FollowUpStaffID").Set(false))
                    .Field(new Field("ActionNote").Set(false))
                    .Field(new Field("EnteredBy").Set(false));

                response.PostEdit += (sender, e) => _LogChange(db, "create", e.Id, e.Values);

                return Json(
                    response.Process(request).Data()
                );
            }
        }

        private void _LogChange(Database db, string action, object id, Dictionary<string, object> values)
        {
            var data = JsonConvert.SerializeObject(values);
            JObject json = JObject.Parse(data);
            DateTime localDate = DateTime.Now;

            db.Insert("CaseActions_History", new Dictionary<string, object>{
                    { "Action", action },
                    { "CaseActionID", id },
                    { "CaseID", json["CaseID"].ToString() },
                    { "ActionID", json["ActionID"].ToString() },
                    { "BillingAmount", json["BillingAmount"].ToString() },
                    { "BilledDate", json["BilledDate"].ToString().NullIfWhiteSpace() },
                    { "CaseDefendantID", json["CaseDefendantID"].ToString() },
                    { "ActionDate", json["ActionDate"].ToString() },
                    { "FollowUpDate", json["FollowUpDate"].ToString().NullIfWhiteSpace() },
                    { "ActionStatusID", json["ActionStatusID"].ToString() },
                    { "FollowUpStaffID", json["FollowUpStaffID"].ToString() },
                    { "ActionNote", json["ActionNote"].ToString() },
                    { "CompletedDate", json["CompletedDate"].ToString().NullIfWhiteSpace() },
                    { "EnteredBy", json["EnteredBy"].ToString() },
                    { "DateUpdated",localDate }
                });
        }
    }

when I look at the variable called json in LogChange function , it is showing FollowUpDate with a value of ""

Answers

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    I’d need a link to a page showing the issue to be able to trace this one through please.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited July 2020

    unfortunately this is on an intranet that I can't give access to. Is there anything else I can provide to help?

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    I think it is going to require tracing through unfortunately - Editor seems to think that values are changing, and I'm not sure why.

    Perhaps the following information might be able to give us a little more information, if you add to your Editor initialisation (i.e. just after you initialise the Editor instance, add the following event handlers):

    editor.on('initEdit', function (e, node, data) {
      console.log('initEdit', JSON.stringify(data);
    });
    
    editor.on('preSubmit', function(e, data, action) {
      console.log('preSubmit', action, JSON.stringify(data);
    });
    

    Then perform the action causing the issue and copy / paste the output shown on the console to here.

    Thanks,
    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    This is a vb.net project so I added the following code:

                    response.PreEdit += (sender, e) =>
                        System.Diagnostics.Debug.WriteLine("PreEdit", e);
    
                    response.WriteEdit += (sender, e) =>
                        System.Diagnostics.Debug.WriteLine("WriteEdit", e);
    
                    response.PostEdit += (sender, e) =>
                        System.Diagnostics.Debug.WriteLine("PostEdit", e);
    

    I could not get the writeLine code to display anything so I added a breakpoint. For the field that says it is getting updated I see the following when I inspect 'e':

    [0] = {[FollowUpDate, ]}
    [0] = {[FollowUpDate, ]}
    [0] = {[FollowUpDate, ]}

    this is when I use: submit: 'changed'. This is the only field being returned.

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    The events I was looking for above are the client-side Javascript ones - not those on the server-side.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    ah, sorry:

    initEdit {"DT_RowId":"row_1059",
    "CaseID":"2",
    "CaseNumber":"5678",
    "CompletedDate":"07/22/2020",
    "DefendantName":"John Doe",
    "ClientName":"Property Owners LLC",
    "ActionName":"Served",
    "StandardBillingRate":"50.00",
    "StatusName":"Completed - In Person",
    "ActionCompleted":"1","
    ActionDate":"07/11/2020",
    "BillingAmount":"199.00",
    "BilledDate":"07/31/2020",
    "BillingStatus":"Billed",
    "CaseDefendantID":"5",
    "ActionID":"1",
    "FollowUpDate":null,
    "ActionStatusID":"2",
    "FollowUpStaffID":"1",
    "ActionNote":"",
    "EnteredBy":"1"}
    
    preSubmit edit {"data":{"row_1059":{
    "FollowUpDate":null}},
    "action":"edit"}
    
  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited July 2020

    ah, I thought it was only when FollowUp date was null that there was an issue, but here is another one:

    initEdit {"DT_RowId":"row_1061",
    "CaseID":"3",
    "CaseNumber":"879649-13",
    "CompletedDate":null,
    "DefendantName":null,
    "ClientName":null,
    "ActionName":"Served",
    "StandardBillingRate":"50.00",
    "StatusName":null,
    "ActionCompleted":null,
    "ActionDate":"07/24/2020",
    "BillingAmount":"50.00",
    "BilledDate":null,
    "BillingStatus":"Action Not Completed",
    "CaseDefendantID":null,
    "ActionID":"1",
    "FollowUpDate":"8/3/2020 12:00:00 AM",
    "ActionStatusID":"0",
    "FollowUpStaffID":"0",
    "ActionNote":"",
    "EnteredBy":"1"}
    
    preSubmit edit {"data":{"row_1061":{
    "CaseDefendantID":null,
    "CompletedDate":null}},
    "action":"edit"}
    
  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    with this record, there was no preSubmit action as it correctly didn't see any changes:

    initEdit {"DT_RowId":"row_1058",
    "CaseID":"1",
    "CaseNumber":"1234",
    "CompletedDate":"07/24/2020",
    "DefendantName":"Henry George",
    "ClientName":"Property Owners LLC",
    "ActionName":"Served",
    "StandardBillingRate":"50.00",
    "StatusName":"Completed - In Person",
    "ActionCompleted":"1",
    "ActionDate":"07/24/2020",
    "BillingAmount":"50.00",
    "BilledDate":null,
    "BillingStatus":"Need to Bill",
    "CaseDefendantID":"6",
    "ActionID":"1",
    "FollowUpDate":"8/3/2020 12:00:00 AM",
    "ActionStatusID":"2",
    "FollowUpStaffID":"1",
    "ActionNote":"asdf",
    "EnteredBy":"1"}
    
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Right - it is the null that is causing an issue. This is a known limitation in Editor's fields - because they write their value to and read it back from input elements there is no way for it to support null. They need to be empty strings unfortunately. Then on the server-side if you get an empty string you can select to write null to the database using a formatter such as ifEmpty.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    so then I would need to do something with getFormatter in my controller to turn nulls to empty?

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Correct - that’s probably what I would do at the moment.

    We do have some ideas for how to handle nulls better, but I’m afraid that will likely be in some future version of Editor as it won’t be trivial to implement.

    Allan

This discussion has been closed.