Newbie with simple Form code question...

gadzilla1gadzilla1 Member Posts: 316
Greetings all!

I am new to the forum and Navision so please forgive my ignorance. :)

I need to put the phone number from the Customer table on the Sales Order form...

The Sales Order form points to the Sales Header table however.

How do I display the Customer.Phone No. in a textbox where Customer.No. = Sales Header.Sell-to Customer No. ? Does anyone have a code sample and where to place it? Thank you!

gadzilla1

Answers

  • SavatageSavatage Member Posts: 7,142
    Can you change code? Do you have a developers license?
  • gadzilla1gadzilla1 Member Posts: 316
    I have the scaled down Application Designers license, not the developers license. So yes I can see and edit much code.

    I'm beginning Navision - my background is VB.NET.

    I'm hoping this is a simple problem, any suggestions? Thank you.
  • mukshamuksha Member Posts: 274
    In the sale header table you have to define a field for contact no. and you have to write a code on sell to customer no. so that it will be copied from customer card and will be stored in the sale header table. Please also flow this to sales invoice header table.
    Mukesh Sharma
  • jversusjjversusj Member Posts: 489
    couldn't you create a C/AL global on the form (CustPhone), where datatype=datatype of phone no. on customer table. then show a control on the form where the source expression equals that variable.

    then, using code define the value of that variable. something like:
    Customer.RESET;
    Customer.GET("Sell to Customer No.");
    CustPhone := Customer."Phone No.";

    you'd want to make sure you put the variable definition in the correct trigger so that as you moved between orders, it would be getting updated.

    this assumes you just want to see the phone number on the sales order form and that you do not want the actual phone number data written to the sales header (muksha's response).

    i cannot modify forms, but i did something similar with a report request form and it worked okay.
    kind of fell into this...
  • SavatageSavatage Member Posts: 7,142
    in other words there are a few ways to do this - one is to add a new field to the Sales Header Table called "Phone No."

    if you look at the code on the table there is a section called
    Sell-to Customer No. - OnValidate()

    If you scroll down enuf you will see where Customer Info gets transfered to the Sales Header.

    Now if you add in.. ( See Red )

    GetCust("Sell-to Customer No.");
    Cust.TESTFIELD(Blocked,FALSE);
    GLSetup.GET;
    IF GLSetup."VAT in Use" THEN
    Cust.TESTFIELD("Gen. Bus. Posting Group");
    "Sell-to Customer Template Code" := '';
    "Sell-to Customer Name" := Cust.Name;
    "Sell-to Customer Name 2" := Cust."Name 2";
    "Sell-to Address" := Cust.Address;
    "Sell-to Address 2" := Cust."Address 2";
    "Phone No." := Cust."Phone No."; //note your change!
    "Sell-to City" := Cust.City;
    "Sell-to ZIP Code" := Cust."ZIP Code";
    "Sell-to State" := Cust.State;
    "Sell-to Country Code" := Cust."Country Code";
    "Sell-to Contact" := Cust.Contact;

    etc, etc

    Now Add "Phone No." to your Sales Header Card.
    *as always if you are not sure what you are doing - first do it in a test database & comment out your code - so it will be easy to be found in the future*

    PS if you want the phone number to also transfer to the Sales Invoice Header - then add the field "Phone No." to the "Sales Invoice Header" using the SAME ID NUMBER - then the transfer will happen without any further code.
  • SavatageSavatage Member Posts: 7,142
    Also all newbies - should check out the application designers guide on the product CD
  • WaldoWaldo Member Posts: 3,412
    Savatage wrote:
    Also all newbies - should check out the application designers guide on the product CD
    Amen! O:)

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • gadzilla1gadzilla1 Member Posts: 316
    Thanks for all the replies, I have a better understanding.

    I was able to add the Phone Number by adding a Flowfield/Lookup to the Sales Header table...that seemed the easiest.

    The only thing is that the end user requested that this phone number field be used to lookup the customer data to populate the sales order, and actually populate fields just like the Sell-To Customer No. does now for new sales orders.

    Is this advisable or possible? I don't want to stir too much if this goes against the Navision grain...


    Also, thanks for the tip on the Application Designer's Guide...good stuff, but for syntax there's not much else out there it seems...
  • SavatageSavatage Member Posts: 7,142
    if you notice..
    when you type in a customer's name into the sell-to customer number - that it will find what you type & change it to the customer number.

    What makes the lookup possible using the customers name (search name I believe) is a property called AltSearchField.

    if you goto desinger of a table and click on a field & view its properties you will see it there. then click on altsearchfield, F1 then for more info.

    So another solution would be to fill in the customer "search name" with their phone number and it should work.

    You can create a report that copies all the phone numbers to the search name field so you don't have to manually enter them. Note - no custs can have the same number else you have a problem.

    Using the Customer Table as a dataitem.
    OnAfterGetRecord()
    Customer."Search Name" := Customer."Phone No.";
    Customer.MODIFY;
    

    If you want to eliminate the dashes you can do that too with code.
    using DELCHR
    OnAfterGetRecord()
    Customer."Search Name" := Customer."Phone No.";
    Customer."Search Name" := DELCHR(Customer."Search Name",'=','-');
    Customer.MODIFY;
    
    I guess it's up to your dataentry people & how they would like to hanlde it.
    These are the 3 things I can come up with..
    #1)Change the AltSearchField to lookup phone numbers
    or #2)making a customer's number their phone number your problem would be solved. ex, 800-212-0038 would be the Cust No.
    or #3)Enter The Phone # into the Search name Field

    personally choice #3 is the easiest and what I would opt for. It's also easy to test. Change one customers Search Name to there Phone number and start a new order. In the Sell-to customer no now enter that phone number, hit enter.

    Anyone else got suggestions?
  • SavatageSavatage Member Posts: 7,142
    Oh PS - New Questions - start a new post - so it will be easier to find for future peeps looking for a similar or same solution. :D
  • gadzilla1gadzilla1 Member Posts: 316
    WOW, thanks for all the help!

    I chose '#1)Change the AltSearchField to lookup phone numbers ' and it works great!

    Also I will make sure to create new posts for new topics.

    Have a great great day! Thanks to everyone.
  • SavatageSavatage Member Posts: 7,142
    Whatever works for you - it's always good to have choices.

    8)
Sign In or Register to comment.