Forcing "OnInsert" Trigger When Importing with Dat

bougeac
bougeac Member Posts: 24
Hi everyone, I am using navision 3.70 and am trying to import a text file into the navision database by using an import dataport.

Ive been able to get all of this working fine and dandy BUT have noticed that the triggers set up on the table i am importing into arent being executed because of the method im using to populate data into it.

I come from an oracle background so am probably getting slightly confused how the triggers in Navision work vs the way Oracle works.

For example, the table has a whole bunch of "OnValidate" triggers set up against certain fields. If I manually type in data into the table via a form, the triggers are launched where appropriate. However, when I import a record into the same table via my dataport, none of the triggers fire.

Obviously this is a major problem as now the validation previously protecting the data isnt kicking in. So I read a bit about triggers etc and settled on putting some code into the dataports "onAfterImportRecord" trigger to force the validation of the tables "trigger" fields by using the "validate" method. This works fine, BUT there is some important auditing code in the underlying tables "OnInsert" trigger that refers to the current records various attributes. I cant seem to force this to fire from the dataport, any ideas on how i can force this trigger to fire???

Cheers in advance,

Chris

Comments

  • Savatage
    Savatage Member Posts: 7,142
    a few tips..

    Go into your dataport and View->Dataport Fields
    if the column isn't showing you can show CallFieldValidate and check off the box next to the field that you need to have "update" other fields.

    that being said (it's doesn't always work, at least for me)
    So what I always do is import data into Variables I created in C/Al Globals and map them to their proper Navision field later and validate the ones I need.

    For example I might want to import a vendor and it's name & address.
    I would create variables like
    MyVendorNo
    MyVendorName
    MyVendorAddress
    MyVendorCity
    MyVendorState
    etc...

    (Note. The Variables above would replace the std nav fields that you enter in View->dataport Fields)

    on the OnAfterImportRecord() //I'll match them & validate
    "No." := MyVendorNo;
    Vendor.VALIDATE("No.");
    Name := MyVendorName;
    Address := MyVendorAddress;
    etc

    This way YOU have total control of what goes where & what get/needs
    validation of checks of anykind.

    etc.
  • Savatage
    Savatage Member Posts: 7,142
    oh i guess i read too fast. you want to have something insert somewhere else on import too?

    here's an example where I want to import Items into the item table, but at the same time populate the "Item Unit Of Measure" table with the proper uom based off the item table.

    //First i use a get
    IF "Item Unit Of Measure".GET(Item."No.", Item."Base Unit of Measure") THEN VALIDATE(Item."Base Unit of Measure")
    ELSE BEGIN
    "Item Unit Of Measure".Code := Item."Base Unit of Measure"; // i transfer the item info to the other table
    "Item Unit Of Measure"."Item No." := Item."No.";
    "Item Unit Of Measure"."Qty. per Unit of Measure" := 1;
    "Item Unit Of Measure".INSERT(TRUE); //force an insert
    VALIDATE(Item."Base Unit of Measure"); //validate for good measure
    END;

    perhaps this is the technique you were looking for?
  • bougeac
    bougeac Member Posts: 24
    Thanks for the tips Harry!

    What you have suggested works fine, but unfortunately its not quite what im looking for...

    See, I can populate the items in the table via my dataport fine, I can also force the ITEM level validation to kick in by using the Validate tool.

    What my problem is (or one of em...) is that the OnInsert trigger at the table level isnt firing, and theres some code in there that has to be executed...

    So in essence, what I need to do, in addition to forcing my "item" level validation is to somehow do "something" to force the "table" level insert trigger to fire...

    Thanks for your help so far buddy.

    Cheers,

    Chris
  • Stardust77
    Stardust77 Member Posts: 95
    Maybe you should set the AutoSave property of that specific table to No, and in the OnAfterImportRecord trigger of the dataport to use INSERT(TRUE). This way, you are going to be sure that the code from OnInsert is run.
  • bougeac
    bougeac Member Posts: 24
    Thanks for your reply stardust,
    very cool name btw!!!

    I think I have got around my problem thanks to you guys input so thanks very much and have a great week-end!!

    chris