Sales Header & Dataport

SavatageSavatage Member Posts: 7,142
edited 2005-08-09 in Navision Attain
Dataports aren't my thing but here goes... #-o

I have a dataport where i want to import a Sales Header & Sales Line info.

It works fine right now, BUT

With the imported data is different SHIP-TO information. Every Cust # is 1234 but the ship-to info is different for every one.

in order to get the customer's complete info in the header I put a VALIDATE("Sell-To Customer No."); on the OnAfterImportRecord of the Sales Header Dataitem.

The problem with this is it put's back the original SHIP-TO INFO for that customer and doesn't keep the imported data.

If I eliminate the VALIDATE line then the ship to data stays but the rest of the customer info is not filled in.

any simple answers out there? I guess I can make two Sales Header Dataitems and have the 2nd import the ship-to address but I figured there has to be another way.

Thanks.

Comments

  • Dean_AxonDean_Axon Member Posts: 193
    What about sending the "Ship-to code" to a variable and then validating it back after you have validated the "Sell-to Customer No." ?
    Remember: Keep it simple
  • SavatageSavatage Member Posts: 7,142
    there are no "ship-to codes" for this customer number. we were manually entering a ship to:

    name
    address
    address2
    city
    st
    zip

    on every sales order.

    These are internet orders so the address could be from anyone/anywhere. We are being a fullfillment center for one customer. So we want to enter the customers number but have the ship-to go whomever ordered the merch over the net.

    We were importing the shipping data into eship which is easy to do - but now we are trying to do an order data feed instead of a shipping data feed. This will enable us to do 3rd party billing for UPS a little easier.
  • fbfb Member Posts: 246
    Is the "Sell-to Customer No." in the input record, or is it a constant value (either hard-coded in the Dataport, or provided on the RequestOptionsForm)?

    If it is in the input record, and it comes 'before' the Ship-to Address fields, then go to the Dataport Fields dialog and set the 'CallFieldValidate' property of the "Sell-to Customer No." field to 'Yes'. Here's a snip from the on-line help for this property, that speaks directly to your issue:
    When fields are imported, they are validated in the same order as they appear in the Field Designer. Note that the code in the OnValidate trigger may or may not initialize other fields in the record, so you should investigate carefully if the order in which the fields are validated is important (by looking at the OnValidate triggers of the fields).
    (Remember to remove the VALIDATE code from the OnAfterImportRec trigger.)

    If the value used is 'constant', then put your code in the OnBeforeImportRec -- probably INIT; followed by VALIDATE("Sell-to Customer No.", constValue);...
  • DenSterDenSter Member Posts: 8,307
    Keep your Sell-to validation, and import the ship-to information into variables. Then after the validation is done, you set the ship to information to the variable values.
  • KaetchenKaetchen Member Posts: 106
    Hi,

    I have to import sales header & sales line from an excel file (dataport) to
    Navision.
    Do you have a dataport?

    My question is:

    1.) Do I need to supply the invoice no. or is it possible the system creates the no., when the customer no. changes?

    Your help would be really appreciated.

    Thanks,
    Stefanie
  • kinekine Member Posts: 12,562
    Savatage:

    Look into Dataport Fields, and go to Show/Hide columns. Show the column "CallFieldValidate". If you check this field, the field will be automatically validated, and if the Sell-to field is before the Ship-to fields, all will be OK (the Customer will be validated first and than all info for ship to will be imported)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    I did try Checking the CallFieldValidate But it didn't seem to do anything.

    So that's why I went with the code. I also read a post or two where other people had the same problem with the CallField Validate not working properly.

    but I will try it again..maybe I missed something - Thanks
  • DenSterDenSter Member Posts: 8,307
    Try this:

    First, you add global text variables for your ship-to fields, so let's say you have MyShipToAddress, and MyShipToCity. Of course you will have more than just two of them, but this is just an example right :).

    Second, you enter these variables into the Field Designer of the dataport, instead of the actual field names of the sales table. All you need to do is handle setting the values in code. Just keep the field "Sell-to Customer No." field in the Field Designer, we'll force the validation later.

    Third, in the OnAfterImportRecord (which fires before the record is modified), you code the following.
    SalesHeader.VALIDATE("Sell-to Customer No.");
    SalesHeader."Ship-to Address" := MyShipToAddress;
    SalesHeader."Ship-to City" := MyShipToCity;
    SalesHeader.MODIFY;
    
    It's important here that you do the validation first and the ship-to fields later, since the Sell-to validation also sets the ship-to information. As you already know, the CallValidation doesn't always work, and because it's hard to predict when, I always just program this kind of stuff right away, saves me a lot of time :). The MODIFY should not be necessary, since the dataport is supposed to do that, so you may want to try it without and test it.
  • SavatageSavatage Member Posts: 7,142
    That code did the trick!

    The Variables seems to be the best way to go. Now with this little bit of knowledge I can fix all those dataport projects that have been sitting on the side!

    CallFieldValidate nice idea if it was reliable :?

    Thanks O:)
  • DenSterDenSter Member Posts: 8,307
    Glad I could help harry :). Oh one more thing.....

    I'm helping a customer with their data migration as it so happens, so I am running into these issues myself. I found that the autoupdate/save/replace doesn't really work either, for some reason I just can't get a dataport to update any records, so I put some code in there as well. At the end of the OnAfterImport trigger, you put this in:
    IF NOT SalesHeader.INSERT THEN
      SalesHeader.MODIFY;
    
    Of course replace the SalesHeader part with whatever dataitem you are working with.

    If the properties don't work then we have more compelling arguments huh :)
  • kinekine Member Posts: 12,562
    IF NOT SalesHeader.INSERT THEN
      SalesHeader.MODIFY;
    

    This code is not good if you have big amount of data for import (on MS SQL). Because it will execute Insert statement for each line which is much more time consuming than Modify (update statement). Faster is to use get to know if the record exist or may be use
    IF NOT SalesHeader.MODIFY THEN
      SalesHeader.INSERT;
    

    But it depend on possibility of inserting new records or modifying old during the import process.

    And the variable solution is common. In "advanced" programming no "standard" dataports exists (I never used dataport without C/AL code). And do not forget, that if you run dataport directly from designer (when you are designing the dataport), it will not commit the changes into database. Run it from object designer instead...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.