0

delete records in dmcf with a button

Hello Ninox Community,

As stated already in the title I would like to delete records chosen in a dynamic multiple choice field. I know that I can deselect them too, but I would like to delete these records with a button.

The above image shows the table and the print layout.

I managed to delete records by

delete 'ausgewählte Dekaden'[Auswahl = 2 or Auswahl=3]

but they are still selected in dmcf and tehrefore in printlayout too.

 

Has anybody an idea how to achieve this?

For better understanding I inserted an example db.

Thanks in advanced.

Regards

Kruna

12 replies

null
    • Fred
    • 11 mths ago
    • Reported - view

    Your delete code:

    delete 'ausgewählte Dekaden'[Auswahl = 2 or Auswahl=3]
    

    does not reference a dMC field. Auswahl is a simple choice field.

    The one dMC field I could find is Mehrfachauswahl (dynamisch) in the Standortauswahl table. The dMC field references the Tabelle1 table.

    Kruna said:
    but they are still selected in dmcf and tehrefore in printlayout too.

    When you said this, it got me thinking that you want to de-select choices in a dMC field, so I'm now not sure what you want to do.

    Do you want to delete records in Dekadenauswahl based on some selection in a dMC field?

    or

    Do you want to remove selections in a dMC field?

    • Kruna
    • 11 mths ago
    • Reported - view

    Hi Fred,

    thank you for helping me here.

    Well actually both I would like to delete all records which are Auswahl !=1 and at the same time de-select the respective choices.

    Lets say eg there are five record and record 1 and 3 are Auswahl=1, then reccord 2, 4, 5 should be deleted in table 'Dekadenauswahl' and de-selected in dmf

    I found out that (ps: actually it was post hepled by you :-)

    https://forum.ninox.com/t/m1hssmn/select-all-choice-in-a-multiple-choice-dynamic )

    for i in numbers(Dekadenauswahl) do
        delete record(Dekaden,i)
    end;

    does the de-select part, but it de-selects all records, but it should de-select only the

    Auswahl !=1

     

    I hope I was able to explain better :-)

    • Kruna
    • 11 mths ago
    • Reported - view

    Hi Fred,

    sorry for confusing you. I will try to show in an screenshot what to hopefully explai bette what i mean.

    First of all:

    for i in numbers(Dekadenauswahl) do
        delete record(Dekaden,i)
    end;

    is not good, as I found out too that it actually deletes the records pointing to table 'Tabelle1' and it should 'just' de-select them.

    The script

    delete 'ausgewählte Dekaden'[Auswahl != 1];

    does exactly what I want to accomplish. Then I need a further script to de-select/remove the respective record 'Test2', so that I can see only 'Test1' and 'Test3'.

    Something like

    if 'ausgewählte Dekaden'[Auswahl != 1] then

    dMC[Auswahl != 1]=null

     

    thx :-)

    • Fred
    • 11 mths ago
    • Reported - view
    Kruna said:
    Then I need a further script to de-select/remove the respective record 'Test2', so that I can see only 'Test1' and 'Test3'.

     That is more clear. My next question is:

    What is the link between Auswahl (a simple choice field) and Tabelle1 (the root of the dMC field)? How do you know that the 2nd record in ‘ausgewahlte Dekaden’ is the 2nd choice in the dMC?

    • Kruna
    • 11 mths ago
    • Reported - view

    Hi Fred,

    I am not quite sure what you mean by 'link between Auswahl (a simple choice field) and Tabelle1 (the root of the dMC field)?'

    Do you mean like in this screenshot?

    How do you know that the 2nd record in ‘ausgewahlte Dekaden’ is the 2nd choice in the dMC?

    I have teh following script in sMC field

    let me := this;
    let cat := concat('ausgewählte Dekaden'.Tabelle1.Nr);
    let multi := numbers('Mehrfachauswahl (dynamisch)');
    for i in multi do
        if not contains(cat, text(i)) then
            let c := (create Dekadenauswahl);
            c.(Haupttabelle := me);
            c.(DekadenBeginn := record(Tabelle1,i).Datum);
            c.(DekadenEnde := record(Tabelle1,i).'Datum 2');
            c.(Dauer := record(Tabelle1,i).Zahl);
            c.(Tabelle1 := number(i))
        end
    end;
    for i in 'ausgewählte Dekaden' do
        if not contains(text(multi), text(i.Tabelle1)) then
            delete i
        end
    end

     

    which creates records once they are chosen. Once I de-select a record in dMC field, the records in 'ausgewählte Dekaden' are deleted, which is correct.

    Now I would like to do delete records with a button. The first part is done by

    delete 'ausgewählte Dekaden'[Auswahl = 2 or Auswahl = 3]

    but the records in dMC fields are still shown. I need to de-select manually, so this should be the done in the second part of the script in the button. Only green choices should be visible in both 'ausgewählte dekaden' and in dMC field at the end of my workflow.

    In table 'Dekadenauswahl' I have three choices to select.

    At the beginning of my post I inserted an example of the database, maybe it helps to understand better what I would like to achieve.

    thx :-)

    • Fred
    • 11 mths ago
    • Reported - view

    You can try the following in a new button to test it out:

    let curDMC := numbers('Mehrfachauswahl (dynamisch)');
    let removeDMC := unique('ausgewählte Dekaden'[Auswahl != 1].Dauer);
    let newDMC := curDMC[var t := this;
            count(removeDMC[!= t]) > 0];
    'Mehrfachauswahl (dynamisch)' := newDMC
    

    Line 1: gets the current selection in the dMC

    Line 2: According to your code Dauer and Zahl seem to link Dekaden to Tabelle1, so here I’m gathering all records in Dekaden where Auswahl does NOT equal 1 and then gather all the Dauer data then only return unique values.

    Line 3: create a new array of records where we remove the number curDMC that is not in removeDMC.

    Line 5: we can then set the dMC field to equal this new array

    You can mix lines 3 and 5 in the future. This way is easier to see what is going on.

    I would recommend that you do this first in your code then delete the record from Dekaden.

    • Kruna
    • 11 mths ago
    • Reported - view

    Good morning Fred,

    first of all thank you so much for your help and patience. I really do appreciate and so great that you explain every line!👍

    I tried your code, doesnt trigger anything and I guess I didnt explain well.

    Maybe I should explain my workflow.

    I have a client who would like to book advertising media.

    Eg, the billboards are booked in decades so there are 34 decades per year, which I have stored in 'Tabelle1'.

    In my example data base I have a main table 'Dekadenplanung'. So first I enter all data eg client, date(start of the project), project number etc. in the main table. The subtable 'Standortasuswahl' of main table contains info about the location of the billboards eg street 1, street, street3, costs xy€ per decade and 'Dauer' shows the days of each decade as a decade here is not necessarily 10.

    Next I have another subtable 'Dekadenauswahl' , which is the subtable of subtable 'Standortasuswahl', where I (de) select decades as decades are availble in one moment, but can be already booked in next moment. This is why I have the choice to mark them in green(available), yellow(alternative) and red(booked) decades in table 'Dekadenauswahl', like eg here:

     

    At the end of the day sometimes there are a lot of decades and often I need to switch depending of availability decades and location of billboards etc.

    My 'last' step in my workflow is to show just the 'green' decades which are therefore available. I

    The yellow button with script

    delete 'ausgewählte Dekaden'[Auswahl !=1]

    does its first step:

    but in dMC field obviously the records are all shown. I would like to de-select them in a button, if possible. In this exapmle it would be record no. 3 and 5.

    Of course I can de-selct them manually by clicking no.3 and no 5 but (what I do now), but in live database would be timesaving, if its possible with a button.

    I hope that I didnt make it more complicated.

    thx :-)

    • Fred
    • 11 mths ago
    • Reported - view

    Sorry there was a bug when multiple records were not Auswahl = 1. Here is the corrected code:

    let curDMC := numbers('Mehrfachauswahl (dynamisch)');
    let removeDMC := unique('ausgewählte Dekaden'[Auswahl != 1].Dauer);
    let newDMC := curDMC[var t := this;
            not removeDMC[= t]];
    'Mehrfachauswahl (dynamisch)' := newDMC
    
    • Kruna
    • 11 mths ago
    • Reported - view

    Hi Fred,

    ok, I understand. I just tried your code, but then it deletes all records.

    Eg in dMC field in trigger after update I have the following code:

     

    let me := this;
    let cat := concat('ausgewählte Dekaden'.Tabelle1.Nr);
    let multi := numbers('Mehrfachauswahl (dynamisch)');
    for i in multi do
        if not contains(cat, text(i)) then
            let c := (create Dekadenauswahl);
            c.(Haupttabelle := me);
            c.(DekadenBeginn := record(Tabelle1,i).Datum);
            c.(DekadenEnde := record(Tabelle1,i).'Datum 2');
            c.(Dauer := record(Tabelle1,i).Zahl);
            c.(Tabelle1 := number(i))
        end
    end;
    for i in 'ausgewählte Dekaden' do
        if not contains(text(multi), text(i.Tabelle1)) then
            delete i
        end
    end

    This code creates a new record in subtable 'Dekadenauswahl'.

    The last part

    for i in 'ausgewählte Dekaden' do
        if not contains(text(multi), text(i.Tabelle1)) then
            delete i
        end
    end

     

    deletes the record once de-selected. As mentioned before, this way I can do it manually. Just looking for a way to achieve with buttom instead.

     

    thx :-)

    • Kruna
    • 11 mths ago
    • Reported - view

    Good morning Fred,

    this is weired. I continue trying out how to get this issue resolved. I entered your code again, yesterday it de-selected all records. Right now it doesnt trigger anything.

    ok, anyway, hope that there might be a solution :-)

    thx :-)

    • Kruna
    • 11 mths ago
    • Reported - view

    Hi,

    I got the help and solution from german forum.

    let me := this;
    let myRecords := 'ausgewählte Dekaden'[Auswahl > 1].number(Tabelle1);
    for ix in myRecords do
        if chosen(me.DMAF, number(ix)) then
            let myArray := numbers(me.DMAF);
            let myNewArray := for iy in myArray do
                    if iy != ix then iy end
                end;
            me.(DMAF := myNewArray)
        end
    end

    did exactly what I was looking for.

    BIG, BIG THANKS to everybody helping me out here and there 👍😀

Content aside

  • Status Answered
  • 11 mths agoLast active
  • 12Replies
  • 173Views
  • 2 Following