NetTalk Central

Author Topic: How to get value from other file and put it to Form file?  (Read 6176 times)

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
How to get value from other file and put it to Form file?
« on: October 23, 2012, 06:03:52 AM »
Hi,

I need to read a file to get the last running number and put it to current form invoice number, may I know how and where can I embed to read the other file value and assign to invoice number?

Another question is, from the example I know that invoice ID must be unique and auto number, in order to link to child file when inserting record. My current file structure is not cater for this and already got stable Win app running. So, can I assign the value to invoice number, then user must Save then only continue on invoice item section? How can I press Save and remain on the form and unhide invoice detail section?

Sorry, I am just new to Nettalk, and rushing program to meet deadline, so post question here.

Thank you.

Robert Iliuta

  • Sr. Member
  • ****
  • Posts: 472
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #1 on: October 23, 2012, 11:12:33 PM »
Hallo,

>I need to read a file to get the last running number and put it to current form invoice number, may I know how

You said your desktop program works, this way you know how correct?
 
>where can I embed to read the other file value and assign to invoice number?

a good embed for this is PreInsert and PreCopy (if you use copy button)

>So, can I assign the value to invoice number, then user must Save then only continue on invoice item section? How can I press Save and remain on the form and unhide invoice detail section?

Here I think you can put a button (not save button, other) to save the first part and disable the fields you want and then continue with the rest...

Hope this helps,
Robert

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to get value from other file and put it to Form file?
« Reply #2 on: October 24, 2012, 04:18:25 AM »
>> I need to read a file to get the last running number and put it to current form invoice number, may I know how and where can I embed to read the other file value and assign to invoice number?

Robert has the right idea.

Another approach is to simply
a) create a function - a normal clarion source function - that returns the number.
b) "Prime" the field you want to prime on the Priming tab, using this function.

Cheers
Bruce



skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #3 on: November 07, 2012, 06:37:12 AM »
Thanks Robert & Bruce, I manage to get the value and assign to invoice number.

But, if more than one person issue invoice, where is the best embed point for me to assign invoice number instead of PreInsert or Prime?

Thank you.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to get value from other file and put it to Form file?
« Reply #4 on: November 07, 2012, 10:26:00 PM »
>> But, if more than one person issue invoice, where is the best embed point for me to assign invoice number instead of PreInsert or Prime?

those are the best embed points - but I'm not sure exactly what problem you are trying to solve with this followup question. So maybe tell us more and we can be more helpful.

cheers
Bruce

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #5 on: November 08, 2012, 06:10:10 AM »
Hi Bruce,

I means few person is open same Invoice Header screen, who press the Save button, who will get the first number, then second number for second person press save.

I found the embed place to do it is CompleteForm, is this the right place?

May I know, like Rebert suggest to put a button to save the invoice header, when should I embed the Save Invoice Header command? And is the command same as Access:InvHdr.Insert?

Thank you.

Best Regards,
Nelson

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to get value from other file and put it to Form file?
« Reply #6 on: November 08, 2012, 10:59:15 PM »
Hi Nelson,

Ok, I think you need to step back a fraction to consider how this works normally.

there are basically two approaches here;

a) when the user opens the form on Insert, you assign the new record number and the record is immediately created. The form is then really in a "Change mode" not an Insert mode. If you then add child records at the same time (like say the Line items for an invoice) then the number is already set, the parent record is already created (remember some backends won't let you create child records before a parent record) and when the user clicks Save they're really just saving the "edits" to the record.

The big advantage with this approach is that it's very easy to do (indeed if you're using auto-numbering the templates do it all for you.) The big disadvantage is that if the user cancels the invoice then you can potentially get a "gap" in the numbering scheme. This is usually nothing to worry about, but in some cases can be unacceptable. (In accounting for example, you aren't really allowed "gaps"). One solution is to mark the record as "cancelled" until they click on save - so the record remains, but is effectively "null and void".

b) The second approach is somewhat more complicated. In this situation you collect the invoice and line items into one or more temporary tables. Then when the user clicks on save you have to manually move the records over to the real table. This can mean no gaps, but it's a lot more effort to do (because you need to do most of the work yourself) and also because you need to deal with a lot more complexity (ie as your form gets more complicated, with more child records, it makes more work.)

I think what you've been thinking about up to now is
"issue the number", then do a bunch of stuff, then create the record when the user clicks on Save. This is really the wrong way to do it because it's harder to manage than (a) above, but doesn't solve (a)s problems.

If the number you are fetching is _not_ an ID field for the table, just an arbitary number, then the better embed point would be the end of the ValidateRecord routine. This is called right before the record is written to disk.

cheers
Bruce

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #7 on: November 12, 2012, 06:28:55 AM »
Hi Bruce,

Thanks for so details explaination.

I have adopted method 1, add auto ID to my Invoice Header & Details for Nettalk control, it is really the easiest way to implement.

BTW, I can't find any example on formula for a field? I need to do like :
Item Amount = (Qty * Unit) - Discount
The formula is no longer applicable, right? Where should I embed?

Thank you.

Best Regards,
Nelson

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to get value from other file and put it to Form file?
« Reply #8 on: November 12, 2012, 07:23:18 AM »
Hi Nelson,

all the fields are "expressions" meaning you can type anything into them.
So, for example, for a browse, you can set it to display
 (Qty * Unit) - Discount
in the "Display" field. (It's one of the template options there.)

this is true all over the templates, you can type in an expression almost everywhere - CHOOSE is a particularly powerful Clarion command in these situations.

cheers
Bruce

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #9 on: November 12, 2012, 10:16:29 AM »
Dear Bruce,

For the browse, I know where to do it, Accounts example shown it.

But for the Form, where is the point to put the "expression"? Don't have the "Display" option?

Thank you.


Regards,
Nelson

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11186
    • View Profile
Re: How to get value from other file and put it to Form file?
« Reply #10 on: November 12, 2012, 09:03:47 PM »
There's a display option if you use the "Display" form field type.
I presume you are wanting to "display" the calculation? I'm not sure how you "enter" a calculation... but if I'm wrong just let me know.

cheers
Bruce

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #11 on: November 13, 2012, 12:42:27 AM »
Hi Bruce,

At the From, I pass value to Source calculate and return a value, how to assign the value and display it?
I want put return value to InvD:TotalPrice and display it once customer amend qty.

I put the following at the InvD:QuantityField -> Refresh Routine
p_web.SetSessionValue('InvD:TotalPrice',GetInvItemTotal(p_web.GetSessionValue('InvD:Quantity'), p_web.GetSessionValue('InvD:UnitPrice'), p_web.GetSessionValue('InvD:DiscountType'), p_web.GetSessionValue('InvD:Discount')))

I tested it can return correct value, but can't assign to InvD:TotalPrice and display it.

Please helps.

TQ!

charl99

  • Full Member
  • ***
  • Posts: 185
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #12 on: November 13, 2012, 01:34:33 AM »
Under Client-Side tab for field quantity, click on send new value to server, put your code there and add a Reset field InvD:TotalPrice 'Value'.

Cheers
Charl

skyong38

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Email
Re: How to get value from other file and put it to Form file?
« Reply #13 on: November 13, 2012, 05:47:23 AM »
Hi Charl,

It helps and problem solved. I don't know why it works under normal field, if I use same method under StockID lookup, it doesn't work. But I can continue the further development.

Thanks a lot!

cheers
Nelson