NetTalk Central

Author Topic: Parent Child Relationships in Mobile Mode  (Read 3630 times)

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Parent Child Relationships in Mobile Mode
« on: June 04, 2014, 07:27:55 PM »
Hi Bruce,

I have an issue where child records cannot be added at the same time the user adds the parent record. It works fine in desktop mode but not in mobile mode. Please see attached example, web73. It's MS SQL so you will need to create an SQL database. You will also need Geoff Bomford's AutoInc template as that's what we use instead of Clarion's AutoInc.

1) Restore the sql database included.
2) Compile and run the app.
3) Open localhost:88.
4) Click 'Customers'.
5) Add a new Customer:
5.1) Add Customer Name.
5.2) Add Customer Country.
5.3) Do NOT click 'Save'.
6) Click the 'Next' button.
7) Click the 'Add Invoice' button.
8) Click the 'Cancel' button. The Customer record is now lost. Even if you save the new Invoice the Customer record is lost.

Is what I'm trying to do possible in mobile mode or do I have to stop users from adding child records before the parent record is inserted and saved?

Regards,
Trent

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: Parent Child Relationships in Mobile Mode
« Reply #1 on: June 04, 2014, 11:30:31 PM »
Hi Trent,

I don't have Geoff's template - but maybe that's a clue as to where the problem is.
In order to create child records, the linking field must be primed with the value from the parent.
Perhaps you need to check if this parent is being set or not?
If not then work backwards from there - is the session value of the parent field set?

cheers
Bruce

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Re: Parent Child Relationships in Mobile Mode
« Reply #2 on: June 05, 2014, 12:51:13 AM »
>> the linking field must be primed with the value from the parent

Just need a bit of clarification on this.

>> is the session value of the parent field set?

In the 'Pre-Insert > End' embed is where I insert a blank record with the GWB template, then change to Net:ChangeRecord if successful and set the parent's ID in the session value:

Code: [Select]
p_web.Trace('Insert Customer succeeded: '& CUS:ID )
 p_web.SSV('CUS:ID',CUS:ID)
 p_web.SetSessionValue('UpdateCustomers:Primed',1)
 p_web.SSV('UpdateCustomers_CurrentAction',Net:ChangeRecord)
 loc:act = Net:ChangeRecord

Is this what you mean?

Regards,
Trent

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: Parent Child Relationships in Mobile Mode
« Reply #3 on: June 05, 2014, 01:36:56 AM »
yes - that's what I mean.
Have you put a TRACE statement in here though to see if CUS:ID actually has any value at this point?

p_web.Trace('Cus:Id=' & p_web.GSV('Cus:Id'))

Later on, when the child record is created, are you priming the Child:CusID = to this session value?

Cheers
Bruce

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Re: Parent Child Relationships in Mobile Mode
« Reply #4 on: June 05, 2014, 01:46:00 AM »
Just put the trace in as per above and the CUS:ID is being set correctly.

Yes I've put the prime in the 'Pre-Insert > End' embed of the UpdateInvoice form:

Code: [Select]
do PrimeInvoice !<<< GWB
INV:Date = today()
INV:Customer = p_web.GSV('CUS:ID')
debug('INV:Customer = '& INV:Customer)
if INV:Customer
  p_web.OpenFile(Customer)
  clear(CUS:Record)
  CUS:ID = INV:Customer
  p_web.SetSQLTimeout(Customer,net:on)
  if access:Customer.tryfetch(CUS:Key)
    debug('Error on access:Customer.tryfetch(CUS:Key), errorcode('& errorcode() &') error('& error() &')')
  end!If
  p_web.SetSQLTimeout(Customer,net:off)
  p_web.CloseFile(Customer)
end!if

The INV:Customer is being set too when adding the Invoice record. The Customer name does not show in the field though.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: Parent Child Relationships in Mobile Mode
« Reply #5 on: June 05, 2014, 06:43:03 AM »
I don't understand your point Trent.

when the child record is saved, is the field being primed there correctly?

trent

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • Email
Re: Parent Child Relationships in Mobile Mode
« Reply #6 on: June 05, 2014, 02:23:04 PM »
Hi Bruce,

You can see the effect in the the normal web73 example (attached). This is using all the default code with Clarion AutoInc:

1) Compile and run.
2) Open localhost:88
3) Click 'Customers'.
4) Click 'Add'.
5) Type in Customer Name.
6) Click 'Next'.
7) Click 'Add Invoice'.
8) Click 'Cancel'. Customer Name and ID are lost. Even if you clicked 'Save' when adding the invoice, the Customer data is still lost. This means you cannot add children while inserting the parent record in mobile mode.

Regards,
Trent

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: Parent Child Relationships in Mobile Mode
« Reply #7 on: July 29, 2015, 01:15:52 AM »
Hi Trent,

ok, what's happening here is a sort of recursive lookup type situation.

You're on the UpdateCustomers form
Which then goes to the UpdateInvoices form
And on this form is a "customers" field (which contains a lookup to the customers table.)

So in this lookup it's "loading the related customer record" (which is blank) and hence blanks the Customer session ID fields.
Hence by the time you get back to the Customer form, the cusomer record has been cleared.

The solution is to suppress the Customer field on the UpdateInvoices form. Now in theory this could be done "always" or it could be done based on some condition. Setting the condition though is tricky, and I don't have a perfect solution for that. So _maybe_ your best option (at least in the near term) is to have a different BrowseInvoices and UpdateInvoices for the UpdateCustomers form.

That said, let's see if a condition is possible. I think it might be, but with some small tweaks to the template (so you'll need build 8.58 or later for this (*).)

The condition, for the lookup field, is

p_web.GSV('UpdateCustomers:Active') = 0

where the UpdateCustomers bit is the "previous procedure" you want to check for.

Now of course there are ways to navigate around this setting. It's set when the form "starts" (in Insert, copy or Change) and is cleared when the user does a successful Save or Cancel.

But, as we know, it's possible to navigate away from a form without using Save or Cancel (menu item, address bar etc) and in that case the session value is not cleared. In a mobile context however this is likely to be much less of an issue.

cheers
Bruce