Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Mapping Industry field...
Sales forum

Mapping Industry field based on NAICS codes

Posted on by Microsoft Employee

Hi there,

I have a excel file that maps NAICS code from Microsoft Insights to industries that my company specializes in.

We have 2 fields in our account form:  NAICS code (which are populated via Insights), and another field called CED Industry which is a picklist of 13 industries.

The excel file maps all the available industries to our specialized industries.

Is there a way I can upload this mapping file (perhaps via xml) so that every time the NAICS code field is populated in the account form, it automatically selects the appropriate CED industry?

Would this be done via JavaScript?

If need be I can share the mapping file. An example line in the mapping file would be:

NAICS, CED Industry

519130, Technology

Categories:
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mapping Industry field based on NAICS codes

    Thank you Ravi!

    This works.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping Industry field based on NAICS codes

    Please note that int the above sample, industryCode contains the value for the optionset field and not the text of the optionset values

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping Industry field based on NAICS codes

    Hi,

    You can refer the below article for the JavaScript basics.

    community.dynamics.com/.../javascript-basics

    Below is the sample JS code which sets the value to undtry optioset field based on the value entered in the code.

    ------------

    function onChangeNAICS() {

       var codeToSearch = Xrm.Page.data.entity.attributes.get("new_naicscode").getValue();

       if(codeToSearch != null)

       {

           // Initialize the value to zero to check before setting it to industry

           var valuereturned = 0;

           // Initialize the Code & Industry Mapping

           var codeIndustrymapping = [];

           codeIndustrymapping.push({ code: '100', industryCode: 100000000 });

           codeIndustrymapping.push({ code: '101', industryCode: 100000001 });

           codeIndustrymapping.push({ code: '102', industryCode: 100000002 });

           codeIndustrymapping.push({ code: '103', industryCode: 100000003 });

           codeIndustrymapping.push({ code: '104', industryCode: 100000004 });

           // Loop through all the available mapping values and set the valuereturned for the maching code.

           for (i = 0; i < codeIndustrymapping.length; i++) {

               if (codeIndustrymapping[i].code === codeToSearch) {

                   valuereturned = codeIndustrymapping[i].industryCode;

               }

           }

       }

       // check if the value is set from the mapping

       if (valuereturned != 0) {

           // if value is set from the mapping, set the value in the industry optionset

           Xrm.Page.data.entity.attributes.get("new_industry").setValue(valuereturned);

       }    

    }

    ------------------------

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mapping Industry field based on NAICS codes

    Hi Ravi,

    Suppose the industry mapping will not change. Would you be able to provide the Javascript examples on how to do that?

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping Industry field based on NAICS codes

    As the mappings will be stored on a different entity, we need to retrieve the value from that entity. To get the values from different entoty, you need to use WEB API.

    You can check this link to get some understanding about retrieveing data from other entity.

    crmjavascripts.blogspot.com/.../retrieve-record-in-crm-2016-using-web.html

    If this a most efficient solution depends about your implementation/ set up. For example, if the mappings will increase/change/delete then this would be the most efficient approach as then you just need to change the record in the entity (add/ delete/ update)

    If you are limited number  of mapping and you are sure that these will not change thent you can go for alternative approach of storing the mapping in javascript array and then use if else to set  the values. In this case, you don't need to create separate entity, or importing the data using excel/ xml. You will store the mapping directly in your javascript file.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Mapping Industry field based on NAICS codes

    Thanks Ravi,

    I'm unclear how to do the following step:

    -- take the NAICS value and then retrieves the respective industry value from the mapping entity [For this, you would need WEB API code]

    Can you explain this a bit more?

    Also, is this the most efficient solution?

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping Industry field based on NAICS codes

    Hi,

    This can be done but with some customization and some JS. The high level approach would be something like this-

    1. Creating a new custom entity which will store the mapping of NAICS code & Industry.

    2. You can easily import data into this entity using excel/ xml.

    3. On account entity, you need to write JavaScript which will

    -- trigger on change of NAICS field-

    -- take the NAICS value and then retrieves the respective industry value from the mapping entity [For this, you would need WEB API code]

    -- Once you get the value of the industry, set that value on the Industry field.

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans