Field won't be saved (preGet)

Field won't be saved (preGet)

mp2000mp2000 Posts: 20Questions: 1Answers: 0
edited March 4 in Editor

Hello,

i would like to have only those entries displayed from a "dropdown", for which you have the corresponding authorization.

this works so far, only that the field "XRM_Timeslips.fa_billingstatus_id" is not saved when sending the form.

       ->on('preGet', function ($editor, $id) {

            $m_user = new User_Model;
            $userid = $_SESSION['login']['userid'];

            if ($m_user->hasPermission("updateEverything", "xrmTimeslips", $userid) == true) {
                $editor
                    ->fields(
                        Field::inst('XRM_Timeslips.fa_billingstatus_id')
                            ->options(Options::inst()
                                    ->table('FA_BillingStatus')
                                    ->value('id')
                                    ->label('Name')
                                    ->where(function ($q) {
                                        $q->where(function ($r) {
                                            $r->where('FA_BillingStatus.id', 4);
                                            $r->or_where('FA_BillingStatus.id', 5);
                                            $r->or_where('FA_BillingStatus.id', 8);
                                        });
                                    })
                            )
                    );
            } else {
                $editor
                    ->fields(
                        Field::inst('XRM_Timeslips.fa_billingstatus_id')
                            ->options(Options::inst()
                                    ->table('FA_BillingStatus')
                                    ->value('id')
                                    ->label('Name')
                                    ->where(function ($q) {
                                        $q->where(function ($r) {
                                            $r->where('FA_BillingStatus.id', 5);

                                        });
                                    })

                            )
                            ->validator('Validate::dbValues')
                            ->validator('Validate::notEmpty')
                    );
            }
        })
 
$(function() {
    var editor;
    editor = new $.fn.dataTable.Editor({
        ajax: "ajax/xrm/timeslips/processData.php",
        table: "#table_[@ID UID]",
        template: '#form_[@ID UID]',
        fields: [{
            label: "ID:",
            name: 'XRM_Timeslips.id',
            type: 'readonly'
        }, {
            label: "FA-Status:",
            name: "XRM_Timeslips.fa_billingstatus_id",
            opts: {
                multiple: false,
                placeholder: 'auswählen'
            },
            "type": "select2",
            
        } ]
    });

Replies

  • allanallan Posts: 49,501Questions: 1Answers: 7,286 Site admin

    If you add ->debug(true) just before the ->process(...) method in the PHP, could you show me the JSON return from the server when you do an edit please?

    Thanks,
    Allan

  • mp2000mp2000 Posts: 20Questions: 1Answers: 0
    edited March 5
    {
        "data": [{
            "DT_RowId": "row_550",
            "XRM_Timeslips": {
                "id": "550",
                "Note": "test",
                "Title": "TEST",
                "NoteInternal": "",
                "FaNumber": "",
                "ChangedBy": "1",
                "DateUpdated": "04.03.2019 15:37",
                "DateCreated": "04.03.2019 10:48",
                "ServiceDate": "04.03.2019",
                "xrm_company_id": "102",
                "xrm_timeslips_performedby_id": "3",
                "AData1": null,
                "xrm_timeslipssource_id": "1",
                "TimeslipSourceTargetId": null,
                "FaSourceId": null,
                "DateStart": null,
                "DateEnd": null,
                "Hours": "1",
                "HoursTotal": "1",
                "xrm_project_id": "1",
                "xrm_timeslipslocation_id": "2",
                "config_verify_id": "1",
                "CreatedBy": "1",
                "fa_billingstatus_id": "8"
            },
            "Config_User_CreatedBy": {
                "Name": "Test",
                "id": "1"
            },
            "XRM_TimeslipsLocation": {
                "Name": "Test"
            },
            "XRM_Company": {
                "CustomerId": "123456",
                "Name": "L\u00d6SCHEN"
            },
            "XRM_Timeslips_PerformedBy_View": {
                "Name": "Test"
            },
            "XRM_TimeslipsSource": {
                "Name": "Sonstiges",
                "UrlOpen": null
            },
            "XRM_Project": {
                "Name": "N\/A"
            },
            "Config_Verify": {
                "Name": "nein"
            },
            "FA_BillingStatus": {
                "Name": "intervallberechnung"
            },
            "XRM_Timeslips_File": []
        }],
        "debug": [{
            "query": "SELECT `id` as 'id' FROM `XRM_Company` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "102",
                "type": null
            }]
        }, {
            "query": "SELECT `id` as 'id' FROM `XRM_Timeslips_PerformedBy_View` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "3",
                "type": null
            }]
        }, {
            "query": "SELECT `id` as 'id' FROM `XRM_TimeslipsSource` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "1",
                "type": null
            }]
        }, {
            "query": "SELECT `id` as 'id' FROM `XRM_Project` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "1",
                "type": null
            }]
        }, {
            "query": "SELECT `id` as 'id' FROM `XRM_TimeslipsLocation` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "2",
                "type": null
            }]
        }, {
            "query": "SELECT `id` as 'id' FROM `Config_Verify` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "1",
                "type": null
            }]
        }, {
            "query": "SELECT * FROM `XRM_Timeslips` WHERE `XRM_Timeslips`.`id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "550",
                "type": null
            }]
        }, {
            "query": "UPDATE `XRM_Timeslips` SET `Note` = :Note, `Title` = :Title, `NoteInternal` = :NoteInternal, `FaNumber` = :FaNumber, `ChangedBy` = :ChangedBy, `ServiceDate` = :ServiceDate, `xrm_company_id` = :xrm_company_id, `xrm_timeslips_performedby_id` = :xrm_timeslips_performedby_id, `xrm_timeslipssource_id` = :xrm_timeslipssource_id, `DateStart` = :DateStart, `DateEnd` = :DateEnd, `Hours` = :Hours, `HoursTotal` = :HoursTotal, `xrm_project_id` = :xrm_project_id, `xrm_timeslipslocation_id` = :xrm_timeslipslocation_id, `config_verify_id` = :config_verify_id WHERE `XRM_Timeslips`.`id` = :where_0 ",
            "bindings": [{
                "name": ":Note",
                "value": "test",
                "type": null
            }, {
                "name": ":Title",
                "value": "TEST",
                "type": null
            }, {
                "name": ":NoteInternal",
                "value": "",
                "type": null
            }, {
                "name": ":FaNumber",
                "value": "",
                "type": null
            }, {
                "name": ":ChangedBy",
                "value": "1",
                "type": null
            }, {
                "name": ":ServiceDate",
                "value": "2019-03-04",
                "type": null
            }, {
                "name": ":xrm_company_id",
                "value": "102",
                "type": null
            }, {
                "name": ":xrm_timeslips_performedby_id",
                "value": "3",
                "type": null
            }, {
                "name": ":xrm_timeslipssource_id",
                "value": "1",
                "type": null
            }, {
                "name": ":DateStart",
                "value": null,
                "type": null
            }, {
                "name": ":DateEnd",
                "value": null,
                "type": null
            }, {
                "name": ":Hours",
                "value": "1",
                "type": null
            }, {
                "name": ":HoursTotal",
                "value": "1",
                "type": null
            }, {
                "name": ":xrm_project_id",
                "value": "1",
                "type": null
            }, {
                "name": ":xrm_timeslipslocation_id",
                "value": "2",
                "type": null
            }, {
                "name": ":config_verify_id",
                "value": "1",
                "type": null
            }, {
                "name": ":where_0",
                "value": "550",
                "type": null
            }]
        }, {
            "query": "DELETE FROM `XRM_Timeslips_Link_File` WHERE `xrm_timeslips_id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "550",
                "type": null
            }]
        }, {
            "query": "SELECT `XRM_Timeslips`.`id` as 'XRM_Timeslips.id', `Config_User_CreatedBy`.`Name` as 'Config_User_CreatedBy.Name', `Config_User_CreatedBy`.`id` as 'Config_User_CreatedBy.id', `XRM_Timeslips`.`Note` as 'XRM_Timeslips.Note', `XRM_TimeslipsLocation`.`Name` as 'XRM_TimeslipsLocation.Name', `XRM_Company`.`CustomerId` as 'XRM_Company.CustomerId', `XRM_Company`.`Name` as 'XRM_Company.Name', `XRM_Timeslips_PerformedBy_View`.`Name` as 'XRM_Timeslips_PerformedBy_View.Name', `XRM_Timeslips`.`Title` as 'XRM_Timeslips.Title', `XRM_TimeslipsSource`.`Name` as 'XRM_TimeslipsSource.Name', `XRM_TimeslipsSource`.`UrlOpen` as 'XRM_TimeslipsSource.UrlOpen', `XRM_Timeslips`.`NoteInternal` as 'XRM_Timeslips.NoteInternal', `XRM_Project`.`Name` as 'XRM_Project.Name', `XRM_Timeslips`.`FaNumber` as 'XRM_Timeslips.FaNumber', `Config_Verify`.`Name` as 'Config_Verify.Name', `FA_BillingStatus`.`Name` as 'FA_BillingStatus.Name', `XRM_Timeslips`.`ChangedBy` as 'XRM_Timeslips.ChangedBy', `XRM_Timeslips`.`DateUpdated` as 'XRM_Timeslips.DateUpdated', `XRM_Timeslips`.`DateCreated` as 'XRM_Timeslips.DateCreated', `XRM_Timeslips`.`ServiceDate` as 'XRM_Timeslips.ServiceDate', `XRM_Timeslips`.`xrm_company_id` as 'XRM_Timeslips.xrm_company_id', `XRM_Timeslips`.`xrm_timeslips_performedby_id` as 'XRM_Timeslips.xrm_timeslips_performedby_id', `XRM_Timeslips`.`AData1` as 'XRM_Timeslips.AData1', `XRM_Timeslips`.`xrm_timeslipssource_id` as 'XRM_Timeslips.xrm_timeslipssource_id', `XRM_Timeslips`.`TimeslipSourceTargetId` as 'XRM_Timeslips.TimeslipSourceTargetId', `XRM_Timeslips`.`FaSourceId` as 'XRM_Timeslips.FaSourceId', `XRM_Timeslips`.`DateStart` as 'XRM_Timeslips.DateStart', `XRM_Timeslips`.`DateEnd` as 'XRM_Timeslips.DateEnd', `XRM_Timeslips`.`Hours` as 'XRM_Timeslips.Hours', `XRM_Timeslips`.`HoursTotal` as 'XRM_Timeslips.HoursTotal', `XRM_Timeslips`.`xrm_project_id` as 'XRM_Timeslips.xrm_project_id', `XRM_Timeslips`.`xrm_timeslipslocation_id` as 'XRM_Timeslips.xrm_timeslipslocation_id', `XRM_Timeslips`.`config_verify_id` as 'XRM_Timeslips.config_verify_id', `XRM_Timeslips`.`CreatedBy` as 'XRM_Timeslips.CreatedBy', `XRM_Timeslips`.`fa_billingstatus_id` as 'XRM_Timeslips.fa_billingstatus_id' FROM `XRM_Timeslips` LEFT JOIN `XRM_Company` ON `XRM_Company`.`id` = `XRM_Timeslips`.`xrm_company_id` LEFT JOIN `XRM_Timeslips_PerformedBy_View` ON `XRM_Timeslips_PerformedBy_View`.`id` = `XRM_Timeslips`.`xrm_timeslips_performedby_id` LEFT JOIN `XRM_TimeslipsSource` ON `XRM_TimeslipsSource`.`id` = `XRM_Timeslips`.`xrm_timeslipssource_id` LEFT JOIN `XRM_Project` ON `XRM_Project`.`id` = `XRM_Timeslips`.`xrm_project_id` LEFT JOIN `XRM_TimeslipsLocation` ON `XRM_TimeslipsLocation`.`id` = `XRM_Timeslips`.`xrm_timeslipslocation_id` LEFT JOIN `Config_Verify` ON `Config_Verify`.`id` = `XRM_Timeslips`.`config_verify_id` LEFT JOIN `FA_BillingStatus` ON `FA_BillingStatus`.`id` = `XRM_Timeslips`.`fa_billingstatus_id` LEFT JOIN Config_User As Config_User_CreatedBy ON `Config_User_CreatedBy`.`id` = `XRM_Timeslips`.`CreatedBy` WHERE (1=1)AND `XRM_Timeslips`.`id` = :where_2 ",
            "bindings": [{
                "name": ":where_2",
                "value": "550",
                "type": null
            }]
        }, {
            "query": "SELECT DISTINCT `XRM_Timeslips`.`id` as 'dteditor_pkey', `XRM_Timeslips_File`.`id` as 'id' FROM XRM_Timeslips as XRM_Timeslips JOIN `XRM_Timeslips_Link_File` ON `XRM_Timeslips`.`id` = `XRM_Timeslips_Link_File`.`xrm_timeslips_id` JOIN `XRM_Timeslips_File` ON `XRM_Timeslips_File`.`id` = `XRM_Timeslips_Link_File`.`xrm_timeslips_file_id` ",
            "bindings": []
        }, {
            "query": "SELECT `id` as 'id', `DateCreated` as 'DateCreated', `Filename` as 'Filename', `Filesize` as 'Filesize', `WebPath` as 'WebPath', `SystemPath` as 'SystemPath' FROM `XRM_Timeslips_File` ",
            "bindings": []
        }],
        "userid": "1"
    }
    
  • allanallan Posts: 49,501Questions: 1Answers: 7,286 Site admin

    Thanks for that! Do you define the fa_billingstatus_id field in the Editor PHP anywhere other than in the preGet event handler? That would define it only when fetching data from the database which is reflected in the SQL statements above where its only used in the SELECT.

    Allan

  • mp2000mp2000 Posts: 20Questions: 1Answers: 0

    if i define it also in:

    $data = Editor::inst($dbIntranet, 'XRM_Timeslips')
            ->debug(false)
            ->fields(
                Field::inst('XRM_Timeslips.fa_billingstatus_id')
    
    or in preEdit/preCreate 
    
            ->on('preEdit', function ($editor, $id, $values) {
                $editor
                    ->fields(
                        Field::inst('XRM_Timeslips.fa_billingstatus_id')
    

    then this throws the following error:

    Duplicate field detected - a field with the name XRM_Timeslips.fa_billingstatus_id already exists.

  • mp2000mp2000 Posts: 20Questions: 1Answers: 0

    do you have an idea?

  • allanallan Posts: 49,501Questions: 1Answers: 7,286 Site admin

    Apologies - I missed your previous reply. If you change the select2 to be just select for the field type, does it then edit correctly? If so, then when it is select2 have a look at the data submitted from the browser in the "headers" section of the XHR of the network inspector.

    Allan

Sign In or Register to comment.