Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / How to validate stagin...
Finance forum

How to validate staging table value before importing to entity tables

(0) ShareShare
ReportReport
Posted on by 1,159

Hi,

I have a custom entity say EntABC having table CustABC and the staging table entABCStaging.

The table is having multiple fields and one of the fields is having 10 characters lets says bagid.

Now when i am importing data using entity with 10 records ,10 records are getting created in the target CustABC table.

However if I am importing the field bagid with 12 characters say "bag001112345" then too i am getting a record created with 10 characters "bag0011123" removing the last 2 characters.

As per my understanding this is a standard way how AX behaves.However client requires that in such case error should be raised.

I have written validation codes in staging table as well as the entity .

I have also checked the methods like validate,postload ,mapentitytodatasource ,etc..but in this cases also the this.bagid ->has value "bag0011123".

so can anyone let me know if there is a way I can get the original value of the field bagid.

Thanks,

Vikas 

  • XPlusPlus Profile Picture
    10 on at
    RE: How to validate staging table value before importing to entity tables

    Thanks for the reply, Bharani. I had tried putting the relation on the VendTable based on the VendId 

    stagingTable.VendId == VendTable.AccountNum

    here is the VendTable relation properties

    Related cordinality : ZeroOne (also tried ExactlyOne)

    Cardinality : ZeroMore

    Relation ship type: Association

    But no luck what so ever. 

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: How to validate staging table value before importing to entity tables

    You could have simply put a relation in the staging table. Then if the value doesn't exist it will throw error. Code is not required. Even though if you want, you can make use of validate write and validate field of entity and can write the code same as you write in table.

  • XPlusPlus Profile Picture
    10 on at
    RE: How to validate staging table value before importing to entity tables

    Hi Vikas,

      I am trying exactly what you were trying to do. Trying to validate the data before inserting data into the staging table and couldn't figure out it yet. I am wondering if you had any luck implementing it?

    I have overwritten the below methods in my entity calss but no luck:

    1) InsertUpdate() - It never get hit during the debugging. (It works when copying/writing the data from staging to target table)

    2) postGetStagingData() - the break point hits but putting logic didn't work. It seems like the data is already written to the staging table.

    Here is the code in the postGetStagingData() on my entity class

    public void postGetStagingData(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
    {
        super(_dmfDefinitionGroupExecution);
        
        
        while select entityTable where entityTable.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId
        {
           
            entityTable.validateWrite();
            
        }
        
    }

    Here is the code validateWrite method on the entity table

    public boolean validateWrite()
    {
        boolean ret;
    
        ret = super();
    
        if(!VendTable::find(this.VendId))
        {
            ret = checkFailed(strFmt('The Vendor %1 is not a valid vendor', this.VendId));
        }
       
        return ret;
    }

    Not sure if the above method are the ones I should be using and couldn't implement it properly or there is another way to implement the validateWrite on the staging before inserting records into it. Any inputs are appreciated.

    Our version is AX 2012 R3

  • Ashok ashok Profile Picture
    35 on at
    RE: How to validate staging table value before importing to entity tables

    Hi,

    postgetstagingdata (entity method)method called before insert to target table.

  • Vikas Mehta 21 Profile Picture
    1,159 on at
    RE: D365 Entity : How to validate staging table value before importing to entity tables

    No there is no set based operation ,

    code on ValidateWrite only works on the main table (target)and not on the staging table .

    I want to know where can i check and restrict the data in the staging table before getting on the target(entity) table.

    I mean is there a method where i can check whats the data in the staging table ?

  • Sukrut Parab Profile Picture
    71,687 Moderator on at
    RE: D365 Entity : How to validate staging table value before importing to entity tables

    Is this entity using set based operation ? If not you can try writing code in table validateWrite method.

  • Vikas Mehta 21 Profile Picture
    1,159 on at
    RE: D365 Entity : How to validate staging table value before importing to entity tables

    Hi Nicolaos,

    Thanks for your reply.

    Lets say if i increase the staging table field size to 12 characters.In that case where shall i write the code to restrict it to write it in the main table after checking the length of the value .

    eg.if(len(entABCStaging.bagid) >10)

    throw error

    ...

    I have tried writing this code in multiple methods but it seems thats not the right way.

    Thanks,

    Vikas Mehta

  • nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: D365 Entity : How to validate staging table value before importing to entity tables

    Since your field and data type length is 10 characters, the value gets cropped as soon as it's first time assigned to variable of that type, or the field itself. So after that point it's too late.

    In AX2012 / AIF each field was validated against a schema, in which case you would get error if some field was longer than what was defined in the schema. But seems like D365FO data management does not validate the fields against any schema.  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Featured topics

Product updates

Dynamics 365 release plans