# PostLoad() in dataentity

**URL:** <https://www.dynamicsuser.net/t/postload-in-dataentity/79040>\
**Category:** Developer Forum\
**Tags:** live, lookup, d365fo, data-management, dynamicsconlive\
**Created:** [September 14, 2023, 7:39am UTC](https://www.dynamicsuser.net/t/postload-in-dataentity/79040 "2023-09-14T07:39:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Musty7](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Musty7](https://www.dynamicsuser.net/u/Musty7)\
**Post date:** [September 14, 2023, 7:39am UTC](https://www.dynamicsuser.net/t/postload-in-dataentity/79040/1 "2023-09-14T07:39:39Z")

</div>

My requirement was to automatically calculate the `CountryCodePrefix` field based on the `Country` field in a custom table called `HAR_ManufacturedInStaging1` in D365 Finance and Operations (D365FO) when importing data from an Excel file.  
Code Snippet:-

public class HAR\_ManufacturedInStaging1 extends common  
{  
///

#  
///  
///   
public void postLoad()  
{  
super();

```
        if (this.Country)
        {
            // Extract the first 3 letters of the country name
            this.CountryCodePrefix = subStr(this.Country, 1, 3);
        }
        else
        {
            this.CountryCodePrefix = " ";
        }

    }

```

}

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [September 14, 2023, 8:18am UTC](https://www.dynamicsuser.net/t/postload-in-dataentity/79040/2 "2023-09-14T08:18:59Z")

</div>

This isn’t the way how to do it. Override mapEntityToDataSource() method of your entity and implement the logic there. Alternatively you could use postGetStagingData(), if you don’t need to support this logic for OData.

But it’s questionable what the prefix is useful for, because it’s not unique. Don’t you rather want to use ISO code ([ISO 3166](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes))?

---

<div class="post-metadata">

**Author:** ![Musty7](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Musty7](https://www.dynamicsuser.net/u/Musty7)\
**Post date:** [September 14, 2023, 8:48am UTC](https://www.dynamicsuser.net/t/postload-in-dataentity/79040/3 "2023-09-14T08:48:10Z")

</div>

Sure! Thank you, yet I’m still getting the data and my necessary solution by using postload(). Definitely, i’ll try this !
