0

do as server vs. local - missing data?

I've got a script on a tab that I run with "do as server". When I do, it always seems to miss manipulating some data--but not all. It does run fast, though.

As soon as I remove the "do as server" it's bulletproof, but it's really slow.

Is this a thing?

Thoughts?

7 replies

null
    • Mel_Charles
    • 1 yr ago
    • Reported - view

    I use do as server on many scripts and have no issues

    on one table i have over 800,000 records and it still works

    is it worth you showing us your script?

      • Kent_Signorini
      • 1 yr ago
      • Reported - view

      Mel Charles 
      This is the Services code I made to work earlier (a few small changes to original in variable/array names).

      I added a 5th category of Service and it stopped working entirely with any data from the new category. I realized that it might be because in the Services table, the Category choices were 1,2,3,4,10 and in the Invoice Items they went 1,2,3,4,5.  So I switched to doing everything with

      text(Category)

      and strings like

      Category:="Grooming Package"

      instead rather than copying the Service.Category to the Invoice Item.Category. It seemed to fix it for the most part.

      When I leave the whole thing as run as server, it almost never correctly copies the category from the Tips items though. Basically never. If I run it locally, then it almost always does. Almost.

      However, in testing more while waiting for replies here, I found that it's also sometimes not copying other parts of the Service to the Invoice Item in either case. It's strange why it would sometimes and not other times when the data is not being changed at all in-between.

      I'm baffled.

      "SERVICES TAB - TRIGGER AFTER HIDE";
      "Synchronize the Invoice Items to the Services tab";
      let t := this;
      "Get all the selected Items into separate arrays";
      let selectedPackagesArray := for itemID in numbers(Packages) do
              record(Services,itemID)
          end;
      let selectedAddonsArray := for itemID in numbers('Add-ons') do
              record(Services,itemID)
          end;
      let selectedAlaCarteArray := for itemID in numbers('À la Carte') do
              record(Services,itemID)
          end;
      let selectedDiscountsArray := for itemID in numbers(Discounts) do
              record(Services,itemID)
          end;
      let selectedTipsArray := for itemID in numbers(Tips) do
              record(Services,itemID)
          end;
      "Create Invoice Items for Items that ARE checked off in the Services tab";
      for packageItem in selectedPackagesArray do
          if count(t.'Invoice Items'[Services = packageItem]) = 0 then
              let ii := (create 'Invoice Items');
              ii.(
                  Services := packageItem;
                  Appointments := t;
                  Quantity := 1;
                  let i := Services.'* Service';
                  let p := Services.'* Price';
                  let s := Services.'* SKU';
                  let t := Services.'* Taxable';
                  let ti := Services.'* Tax Included';
                  'Invoice Item Service' := i;
                  Price := p;
                  SKU := s;
                  Category := "Grooming Package";
                  Taxable := t;
                  'Tax Included' := ti
              )
          end
      end;
      for addOnItem in selectedAddonsArray do
          if count(t.'Invoice Items'[Services = addOnItem]) = 0 then
              let ii := (create 'Invoice Items');
              ii.(
                  Services := addOnItem;
                  Appointments := t;
                  Quantity := 1;
                  let i := Services.'* Service';
                  let p := Services.'* Price';
                  let s := Services.'* SKU';
                  let t := Services.'* Taxable';
                  let ti := Services.'* Tax Included';
                  'Invoice Item Service' := i;
                  Price := p;
                  SKU := s;
                  Category := "Add-on";
                  Taxable := t;
                  'Tax Included' := ti
              )
          end
      end;
      for aLaCarteItem in selectedAlaCarteArray do
          if count(t.'Invoice Items'[Services = aLaCarteItem]) = 0 then
              let ii := (create 'Invoice Items');
              ii.(
                  Services := aLaCarteItem;
                  Appointments := t;
                  Quantity := 1;
                  let i := Services.'* Service';
                  let p := Services.'* Price';
                  let s := Services.'* SKU';
                  let t := Services.'* Taxable';
                  let ti := Services.'* Tax Included';
                  'Invoice Item Service' := i;
                  Price := p;
                  SKU := s;
                  Category := "À la Carte";
                  Taxable := t;
                  'Tax Included' := ti
              )
          end
      end;
      for discountItem in selectedDiscountsArray do
          if count(t.'Invoice Items'[Services = discountItem]) = 0 then
              let ii := (create 'Invoice Items');
              ii.(
                  Services := discountItem;
                  Appointments := t;
                  Quantity := 1;
                  let i := Services.'* Service';
                  let p := Services.'* Price';
                  let s := Services.'* SKU';
                  let t := Services.'* Taxable';
                  let ti := Services.'* Tax Included';
                  'Invoice Item Service' := i;
                  Price := p;
                  SKU := s;
                  Category := "Discount";
                  Taxable := t;
                  'Tax Included' := ti
              )
          end
      end;
      for tipItem in selectedTipsArray do
          if count(t.'Invoice Items'[Services = tipItem]) = 0 then
              let ii := (create 'Invoice Items');
              ii.(
                  Services := tipItem;
                  Appointments := t;
                  Quantity := 1;
                  let i := Services.'* Service';
                  let p := Services.'* Price';
                  let s := Services.'* SKU';
                  let t := Services.'* Taxable';
                  let ti := Services.'* Tax Included';
                  'Invoice Item Service' := i;
                  Price := p;
                  SKU := s;
                  Category := "Tip";
                  Taxable := t;
                  'Tax Included' := ti
              )
          end
      end;
      "Remove Invoice Items for Items that are NOT checked off in Services tab";
      for invoiceItem in select 'Invoice Items' do
          if invoiceItem.Services != null then
              let isCheckedOff := false;
              for id in selectedPackagesArray do
                  if invoiceItem.Services = id then
                      isCheckedOff := true
                  end
              end;
              for id in selectedAddonsArray do
                  if invoiceItem.Services = id then
                      isCheckedOff := true
                  end
              end;
              for id in selectedAlaCarteArray do
                  if invoiceItem.Services = id then
                      isCheckedOff := true
                  end
              end;
              for id in selectedDiscountsArray do
                  if invoiceItem.Services = id then
                      isCheckedOff := true
                  end
              end;
              for id in selectedTipsArray do
                  if invoiceItem.Services = id then
                      isCheckedOff := true
                  end
              end;
              if isCheckedOff = false then delete invoiceItem end
          end
      end
      

      Here is a link to a video of it in happening:

      https://www.dropbox.com/s/ouyt5bwsarz6wlh/do%20as%20server.mov?dl=0

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      Kent Signorini This would happen if two users made a change at the same time. The last one to enter the information would win.

      As there is no other user at the same time, it may be another code that runs at the same time and competes with the first.

      If this other code is on the sever, then when the first one runs locally, it is always slower and registers the information last. When they are both on the server, it is the second code that is slower (or runs after the first one).

      Is there a trigger or a field dependent on the Category field. Or trigger like After Update or On New Record ?

      What happens if you place the ball of the "Tip" category first in your code, before the other categories?

      • Kent_Signorini
      • 1 yr ago
      • Reported - view

      Jacques TUR Thanks for this. Very good to know.

    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    Some functions are executed locally and some server sided. Check this list of differences : https://docs.ninox.com/en/script/appendix/transactions/execution-context

      • Kent_Signorini
      • 1 yr ago
      • Reported - view

      RoSoft_Steven Not that I can tell. Hm.

    • Kent_Signorini
    • 1 yr ago
    • Reported - view

    I SOLVED IT! (At least it appears to be solved...)

    I'm pretty sure it's related to something I mentioned in my earlier reply. In the Services items, the Category choice looked like this:

    Whereas, in the Invoice Items, Category looked like this:

     

    I'm almost 100% certain that it has to do with the fact that Tip is #11 in Services and #7 in Invoice Items.

    To solve it, I deleted the Category fields from both places and rebuilt them. Now, everything is numbered 1...5 in both places. I had to do a lot of relinking, Services data export and re-import, and very closely check code.

    But now, it works.

    I think somehow the iteration of the Choices (perhaps the problem is on the Ninox backend) it gets lost when there is a gap between the Choice value #'s and/or the #'s aren't sequential. 

    I even tested this by making Tip #11 in Invoice Items (added and deleted some junk choices until Tips was #11) and it didn't work. So it might not have been that the #'s were different, but that there was a gap in the numbers.

    With everything sequential and with no gaps, Tips now works, just like the other Categories.

    So happy.

    (And it works "as server", too! Nice and fast!)

Content aside

  • 1 yr agoLast active
  • 7Replies
  • 116Views
  • 4 Following