web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Import Validation

(0) ShareShare
ReportReport
Posted on by 13

Hi all,

DestinationGroupLine  destinationGroupLine;

select firstonly destinationGroupLine
	where destinationGroupLine.DestinationGrpId ==  destinationGroup.DestinationGrpId
	&&  destinationGroupLine.Country ==  range.get_Item(rowNo,2).Value
	&& destinationGroupLine.City ==  range.get_Item(rowNo,3).Value;

if(!destinationGroupLine.RecId)
{
	//LogisticsAddressCity logisticsAddressCity;
	//LogisticsAddressCounty logisticsAddressCounty;

	//select firstonly logisticsAddressCity
	//    where logisticsAddressCity.Name ==  range.get_Item(rowNo,3).Value;

	//select firstonly logisticsAddressCounty
	//    where logisticsAddressCounty.Name ==  range.get_Item(rowNo,2).Value;

	destinationGroupLine.clear();
	destinationGroupLine.DestinationGrpId = destinationGroup.DestinationGrpId;
	destinationGroupLine.Country = range.get_Item(rowNo,2).Value;
	destinationGroupLine.City = range.get_Item(rowNo,3).Value;
	if(destinationGroupLine.validateWrite())
	{
		destinationGroupLine.doInsert();
	}
}

As i mentioned above code works fine for me. now, if i add country IND and city (Madina) like example.

I want to warning IND not available "madina".

1.Only if already exist country against the city only insert otherwise error thrown. 

2. same country only if exists country will insert otherwise error thrown.

Two validation i want to do while importing excel so that what to be done ?

Thanks 

I have the same question (0)
  • GirishS Profile Picture
    27,833 Moderator on at

    Hi Lakshmi,

    You can use "LogisticsPostalAddress" table to validate city against country and vice versa.

    LogisticsPostalAddress will have this information against city, district, state, county and country.

    Thanks,

    Girish S.

  • Lakshmi Profile Picture
    13 on at

    Thanks for your replay Girish,

    Can u give me a example for this validation ?

  • Verified answer
    GirishS Profile Picture
    27,833 Moderator on at

    You can try like something below.

    LogisticsPostalAddress postalAddress;
    //validation of city against country
    select firstOnly * from postalAddress
        where postalAddress.Country == range.get_Item(rowNo,2).Value
        && postalAddress.City == range.get_Item(rowNo,2).Value;
    if(postalAddress)
    {
       // insert records
    }
    else
    {
        //throw warning.
    }

    Thanks,

    Girish S.

  • Lakshmi Profile Picture
    13 on at

    Thanks for prompt response :)

  • Lakshmi Profile Picture
    13 on at

              if(!destinationGroupLine.RecId)
                {
                    LogisticsPostalAddress postalAddress;
                    
                    select firstOnly * from postalAddress
                    where postalAddress.County == range.get_Item(rowNo,2).Value
                    && postalAddress.City == range.get_Item(rowNo,3).Value;
    
                    if(postalAddress)
                    {
                        destinationGroupLine.clear();
                        destinationGroupLine.DestinationGrpId = destinationGroup.DestinationGrpId;
                        destinationGroupLine.Country = range.get_Item(rowNo,2).Value;
                        destinationGroupLine.City = range.get_Item(rowNo,3).Value;
                        if(destinationGroupLine.validateWrite())
                        {
                            destinationGroupLine.doInsert();
                        }
                    }
                    else
                    {
                        warning(strFmt("Country and city does't exist %1",desGrpId));
                    }
            }

    Hi Girish, i have debugged above code if(postalAddress) not come else part warning thrown even if country and city available.

    What could be the reason ? 

  • GirishS Profile Picture
    27,833 Moderator on at

    On line number 6 it should be CountryRegionId right not county.

    Thanks,

    Girish S.

  • Lakshmi Profile Picture
    13 on at

    select firstOnly * from postalAddress
        where postalAddress.CountryRegionId == destinationGroupLine.Country  //Country region id EDT 
        && postalAddress.County == range.get_Item(rowNo,2).Value
        && postalAddress.City == range.get_Item(rowNo,3).Value;

    You mean like : if so, its also not working else part thrown again.

  • GirishS Profile Picture
    27,833 Moderator on at

    No, where you will get the CountryRegionId.

    You need to validate Country with City and Country with County right?

    Just open the LogisticsPostalAddress in table browser and see your values are there against City, County and CountryRegionId.

    Thanks,

    Girish S.

  • GirishS Profile Picture
    27,833 Moderator on at

    If you want to validate Country with City and County use LogisticsAddressCity table.

    LogisitcsAddressCity addressCity;
    // I am assuming the country region id as "IND"  and validate city and county against CountryRegionId             
    select firstOnly * from addressCity
        where addressCity.County == range.get_Item(rowNo,2).Value
        && addressCity.Name == range.get_Item(rowNo,3).Value
        && addressCity.CountryRegionId == "IND";
    if(addressCity)
    {
        //insert code
    }
    else
    {
        throw error
    }

    Thanks,

    Girish S.

  • Lakshmi Profile Picture
    13 on at

    DestinationGroupLine  destinationGroupLine;
    
        select firstonly destinationGroupLine
            where destinationGroupLine.DestinationGrpId ==  destinationGroup.DestinationGrpId //header grpid
            &&  destinationGroupLine.Country ==  range.get_Item(rowNo,2).Value
            && destinationGroupLine.City ==  range.get_Item(rowNo,3).Value;
       
        if(!destinationGroupLine.RecId)
        {
            LogisticsAddressCity addressCity;
            
            select firstOnly * from addressCity
            where addressCity.CountyId == range.get_Item(rowNo,2).Value
            && addressCity.Name == range.get_Item(rowNo,3).Value
            && addressCity.CountryRegionId == destinationGroupLine.Country;
    
            if(addressCity)
            {
                destinationGroupLine.clear();
                destinationGroupLine.DestinationGrpId = destinationGroup.DestinationGrpId;
                destinationGroupLine.Country = range.get_Item(rowNo,2).Value;
                destinationGroupLine.City = range.get_Item(rowNo,3).Value;
                if(destinationGroupLine.validateWrite())
                {
                    destinationGroupLine.doInsert();
                }
            }
            else
            {
                warning(strFmt("Country and city does't exist %1",desGrpId));
            }
        }

    Same thing not working. same else part error thrown.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 517 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 440

#3
Adis Profile Picture

Adis 266 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans