0

Trying to "hide" records in main table

I am trying to "hide" records in my main table (Orders) by having them move to sub table (Received) when the field (Received by)= 1, 2, or 3. I am not sure how to write the code correctly to get it to do what I want.

19 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    There is no "Move" command so you will have to hard code the copying of data field by field from the Orders table to the Received table. There will also be many steps to get to your desired results so let us take it one step at a time.

     

    First make sure you are in a DB that you can mess with as you will be testing out creation of records and deletion of records.

     

    To test the creation of a new record in the Received table you can put something like this in a button on your Orders table:

     

    let curRec := this;<--this line gathers all the data of the current record

    let newReceived := (create Received);<--here we tell Ninox to create a new record in the Received table

       newReceived.(Field1 := curRec.Field1);<--now we tell Ninox to copy the data from our current record into the newly created record in the Received table

       newReceived.(Field2 := curRec.Field2)<--copy the next field, the last copy line does not need the semicolon.

     

    If that works then you add the delete function. Again make sure you can safely delete this record. You can add the following to the above code:

     

    delete curRec

     

    I'll add the loop function in another post where it will look for 'Received by' and then run the code.

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    Thanks for responding. I am fairly new with Ninox, and I'm not sure exactly where I need to put the code above. What sort of button are you referring to?

    • Fred
    • 2 yrs ago
    • Reported - view

    Hi Hardy -

     

    A button is a "layout element". If you go to Edit Fields you will see on the right side Add layout element. From there you can add a button.

     

    When you double click on the button field you will then add code to the On click section of the button.

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    Update: I found the button option under layout, however when I am inputting the code in does not recognize my field names.

    For example:

    let curRec := this;
    let newReceived := (create Received);
    newReceived. ('Ordered by' := curRec.'Ordered by');

    This is what I have so far and it is saying field not found

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    I have made some progress. I currently have the following code:

    let curRec := this;
    let newReceived := (create Received);
    newReceived;
    'Ordered by' := curRec.'Ordered by';
    newReceived;
    'Ordered on' := curRec.'Ordered on';
    newReceived;
    Vendor := curRec.Vendor;
    newReceived;
    'Order type' := curRec.'Order type';
    newReceived;
    'Ordered late' := curRec.'Ordered late';
    newReceived;
    'Received by' := curRec.'Received by';
    newReceived;
    'Received on' := curRec.'Received on';
    newReceived;
    'Line code' := curRec.'Line code';
    newReceived;
    'Part number' := curRec.'Part number';
    newReceived;
    Quantity := curRec.Quantity;
    newReceived;
    Quoted := curRec.Quoted;
    newReceived;
    Freight := curRec.Freight;
    newReceived;
    Paid := curRec.Paid;
    newReceived;
    Deliver := curRec.Deliver;
    newReceived;
    'Customer name' := curRec.'Customer name';
    newReceived;
    'Phone number' := curRec.'Phone number';
    newReceived;
    Notes := curRec.Notes

     

    Which does create a record in the sub table "Received", but does not copy the information over. I am now stuck and cannot figure out how to correct this.

    Thanks!

    • Fred
    • 2 yrs ago
    • Reported - view

    Just wondering, did you create the same field and field names in the Received table?

     

    The second post code doesn't work cause you have a semicolon after newReceived thus ending the line. What you wrote is telling Ninox to take the data in Paid and copy it to same Paid field.

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    Yes I have the same fields on the Received table. What would be the correct way to code that to have the data copy over to the Received table when we input in the Orders table?

    • Fred
    • 2 yrs ago
    • Reported - view

    what you wrote should work. i noticed that there is a space after "newReceived.". There shouldn't be any spaces.

    let curRec := this;
    let newReceived := (create Received);
    newReceived.('Ordered by' := curRec.'Ordered by');

     

    When you type newReceived. then start typing the name of the field does it bring up the field name for you to select?

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    I corrected my code and made sure my fields were exactly the same and it is working now. Will the button need to be pressed every time a new record is created to have it copy to "Received" or is there a way to automate that? Thank you so much for your help

    • Mel_Charles
    • 2 yrs ago
    • Reported - view

    Hardy

    Depending on what the field (Receive by) is - ie text field

    I would have though you could test for the script to run on trigger after update on that field.

    so instead of having the code in button you put it in that field

    and pre test it to say if 'required by' = 1 etc then run the script!

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    I believe Fred had some more thoughts for what we're currently working on, but I'm just curious. Would I need to put each script in the respective field under trigger after update? How would the code look for the if 'received by'=1,2,or 3 look?

    • Fred
    • 2 yrs ago
    • Reported - view

    Hi Hardy -

     

    Glad the button is working. What Mel suggest is still two steps away, I am breaking down the steps so you can understand what is going on. Plus it is always a good to test scripts like this in a button that you can control before applying it.

     

    The next step is to add an if statement before the code so it will only create a new record when 'Received By' = 1 or 2 or 3.

     

    We will stay with the button until the code is finished. Add the following:

     

    if 'Received By' = 1 or 'Received By' = 2 or 'Received By' = 3 then

    current code

    end

     

    If that all works then you can copy the button code to the Trigger after update part of the 'Received By' field, if that is when you want Ninox to check to see if it needs to copy the record. Otherwise put in the field that makes most sense for your workflow.

     

    Good luck and let us know how it goes.

    • Fred
    • 2 yrs ago
    • Reported - view

    I forgot to answer your first question.

     

    "Would I need to put each script in the respective field under trigger after update?"

     

    I'm not sure what you mean by "each script".

     

    If you have multiple scripts that do different things, it would all depend on when you need them to happen. You can put them at the field level or you can put them at the table level.

    • Mel_Charles
    • 2 yrs ago
    • Reported - view

    Hardy

    I was just answering your question - ie Can you automate it rather than have it triggered by pressing a button. Which you can... by using the " if this fields data has changed can it do the copy record info etc"

    However - I totally agree with FRED let him show you a walk through path first!. He is giving you really good advice.

    What you will learn is there are many ways that you can achieve the same result for a given set circumstances.

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    Fred,

    Thanks you for explaing what you are doing and why as it is helping me understand how to do this. When I input your suggestion before the rest of the code it says "field not found: current at line 1, column 75. I am not sure if I have something formatted incorrectly. This is what I have currently:

    if 'Received By' = 1 or 'Received By' = 2 or 'Received By' = 3 then
    current code
    end
    let curRec := this;

    Along with the rest of the code. Do I have something wrong here?

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    Mel thank you for your input. I am definitely beginning to figure that out!

    • Fred
    • 2 yrs ago
    • Reported - view

    are you putting the code we already worked on between the if and end?

    • Blah
    • Hardy
    • 2 yrs ago
    • Reported - view

    I found a typo and corrected it and everthing is working fine now. I tested it and it does exactly what I need. Does this mean I am ready to put the code in the trigger after update section of 'Received by'? If I do this that means that whenever 1, 2, or 3 is selected in that field it will run the code correct?

    • Fred
    • 2 yrs ago
    • Reported - view

    You ask if you change 'Received by' to 1,2 or 3 will trigger the script. I'm guessing you have tested out each true scenario and a false (when 'Received by' = 4, or whatever a false is) and found that it worked to your satisfaction.

     

    The next step is to put the code into the Trigger after Update of 'Receive by' and test it again. Change 'Received by' to a true and a false case and make sure it does what it is supposed to do.

Content aside

  • 2 yrs agoLast active
  • 19Replies
  • 428Views