Announcements
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
Thank you Ravi!
This works.
Please note that int the above sample, industryCode contains the value for the optionset field and not the text of the optionset values
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);
}
}
------------------------
Hi Ravi,
Suppose the industry mapping will not change. Would you be able to provide the Javascript examples on how to do that?
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.
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?
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.
André Arnaud de Cal...
294,079
Super User 2025 Season 1
Martin Dráb
232,860
Most Valuable Professional
nmaenpaa
101,158
Moderator