0

Create new records with a button

Hello! 

I've been learning a lot with Ninox and this forum has been very helpful.

This is the first time that I would be creating a button. But I think it is possible to make the process easier and avoid adding each record individually.

This is for our inventory system. I have a table for all items called "Articulos", I have a table for purchase orders which is called "Ordenes de Compra" and that table has a subtable called "Compras" that has every line item associated with that purchase order.

I also have a table where I add all the vendors information. So the field vendor on both Items and purchase orders tables have the same relationship to the vendors table.

I want to add a button to the purchase order table that when I select a vendor it can add the items that are low in stock and need to be purchased from that specific vendor. 

In the Items table the field "Comprar" is the number of items that need to be purchased. So I want to add the Items that have the vendor that I select and that have a "Comprar" value >0

Can you please help me with the code for this button?

13 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    Can you upload a sample DB with sample data?

      • German_Caldera
      • 1 yr ago
      • Reported - view

       Yes! Definitely! How can I download the DB?

      • Fred
      • 1 yr ago
      • Reported - view

       

      If you have access the MacOS app you can create an archive:

      1. open your DB and enter admin mode
      2. select the table name at the top left
      3. select Table from the app Menu
      4. Select Export data > select Ninox
      5. click on Save as

      If you have a Professional license for the cloud, then you can download a backup. I don't have a Pro license so I can't go over the steps.

      If you have a start license and no MacOS app then you can invite me to your workspace.

      • German_Caldera
      • 1 yr ago
      • Reported - view

      Thank you so much! I sent you a message.

    • Fred
    • 1 yr ago
    • Reported - view

    Take a look at the first record in the Ordenes de Compra table.

    At the bottom are two new fields, Compras with Proveedores (ComprasProv) and Articulos greater than 0 (Art0).

    The record Ids in ComprasProv are from the Compras table where the vendor record Id equals that of the selected field in Proveedor in the Ordenes de Compra table. We have to do this first step because you don't have a direct relationship between proveedor and articulos.

    The record Ids in Art0 are related Articulos records from the record Ids returned in ComprasProv that have a  Comprar greater than 0.

    Please play around with selecting different proveedors and checking that appropriate Articulos show up in Art0.

      • German_Caldera
      • 1 yr ago
      • Reported - view

       Hey! I did create a relationship between "Articulos" and "Proveedores". It's just that I have only assigned a preferred vendor to the items under the category "Cajas". I haven't assigned the preferred vendor to the rest of the items.

      • Fred
      • 1 yr ago
      • Reported - view

      Ok, so I changed Art0 to look directly into Articulos. Play around to make sure it pulls the correct records.

      • German_Caldera
      • 1 yr ago
      • Reported - view

       It is correct! It is pulling up the right items.

    • Fred
    • 1 yr ago
    • Reported - view

    I did a slightly new flow. I created a new Page called Data Entry. There you will see a list of Proveedores. You will see two fields with one that shows all related Articulos and another that shows related Articulos with a Comprar > 0.

    If you click on the button it will create a new Ordenes de Compra then create a new record in Compras for each record Id that you saw listed in the field showing records with Comprar > 0. Then it will open up that record up for further editing.

    Here is the code:

    let t := this;
    let listofArticulos := Proveedores.Articulos[Comprar > 0];
    let newOrdenes := (create 'Ordenes de Compra');
    for loop1 in listofArticulos do
        let newCompras := (create Compras);
        newCompras.(
            'Ordenes de Compra' := newOrdenes;
            Articulos := loop1
        )
    end;
    openRecord(newOrdenes)
    
      • German_Caldera
      • 1 yr ago
      • Reported - view

       Ok Awesome! I'm taking a look and testing now.

    • Fred
    • 1 yr ago
    • Reported - view

    I also created a button in Ordenes de Compra called add Items and it will add items to the current record you are on.

      • German_Caldera
      • 1 yr ago
      • Reported - view

       That button "Add Items" in Ordenes de Compra is exactly what I needed. Works perfectly. 

      I added a line to also add the value of "Comprar" to each item. It took me a while to figure out how the loop works but I got it.

      let t := this;
      let listofArticulos := Proveedor.Articulos[Comprar > 0];
      for loop1 in listofArticulos do
          let newCompras := (create Compras);
          newCompras.(
              'Ordenes de Compra' := t;
              Articulos := loop1;
              'Cantidad (cases)' := loop1.Comprar
          )
      end

       

      I really appreciate your help, just one question. I believe the table Data Entry is not necessary and I can delete it, right?

      • Fred
      • 1 yr ago
      • Reported - view

      yes you can delete data entry. but if you are creating a db for other users you may want to consider creating Pages that users use instead of inputting data directly into your tables. This way you can do security checks and data validation.

Content aside

  • 1 yr agoLast active
  • 13Replies
  • 319Views
  • 2 Following