Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

FetchXml on stringmap returns no value for objecttypecodename

(0) ShareShare
ReportReport
Posted on by 6

I need to run a FetchXml to get the possible Option Set Values, but when I build the FetchXml based on objecttypecodename nothing is returned:

<fetch>
<entity name="stringmap" >
<attribute name="value" />
<attribute name="objecttypecode" />
<attribute name="objecttypecodename" />
<filter type="and" >
<condition attribute="objecttypecodename" operator="eq" value="account" />
</filter>
</entity>
</fetch>

For example this returns nothing.  Now if I use objecttypecode and 1 it works, but even in code when I run this and return objecttypecodename as a field it's empty in all cases.  I've seen some posts where this is used to select values from StringMap in code for custom lookups and such, but given objectypecode on custom entities can change between organizations I need to somehow query on entityname instead.  Any ideas if this is a bug or if someone has other suggestions on how to do this?  We're using Dynamics 365 (CRM 2015 - v8) on prem.

Here's an article that actually suggests this method:
https://community.dynamics.com/crm/b/crmtipsfromadeveloper/posts/know-how-d365-crm-get-optionset-label-from-stringmap-using-fetchxml-c-js-ssrs

Thanks.

*This post is locked for comments

  • Suggested answer
    Martin Donnelly Profile Picture
    1,030 on at
    RE: FetchXml on stringmap returns no value for objecttypecodename

    Here's some ideas that might help.  I think all the typecodes are the same for out of the box so, the problem is finding those for custom.  I think they all start at 10000.  Also, I'm guessing one cannot run a comparison against the virtual field to explain why it is not found.

    So... maybe you need to fetch a set where objectypecode ge 10000, run the set looking for the entity name in objecttypecodename and use that record which matches.

    If you are looking for something completely generic the forget the ge 10000 and search through the whole set.  It can't be so big as to be a performance issue.

  • samalex1701 Profile Picture
    262 on at
    RE: FetchXml on stringmap returns no value for objecttypecodename

    Yes it's listed when I check the Metadata of the Entity through XRM Toolbox:

    pastedimage1573768462348v1.png

    But every query I create using objecttypecodename does not work or gives an error saying it doesn't exist.  

  • cloflyMao Profile Picture
    25,208 on at
    RE: FetchXml on stringmap returns no value for objecttypecodename

    Hi Partner,

    Have you confirmed that whether objecttypecodename field is actually existed in stringmap entity in your CRM environment?

    Could you share me posts you've seen which tell us how does objecttypecodename field work?

    In addition, my environment is Dynamics 365 v9 online,

    I downloaded and imported a solution called Metadata Browser, selected stringmap entity and found objecttypecode is actually entityname.

    pastedimage1565319047615v1.png

    And I execute web API script to retrieve stringmap entity records and still not found objecttypename field.

    var req = new XMLHttpRequest();
    req.open('GET', Xrm.Page.context.getClientUrl() + "/api/data/v9.0/stringmaps?$filter=objecttypecode eq 'account'", false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Prefer", "odata.include-annotations=*");
    req.send();
    if (req.readyState == 4 /* complete */) {
        if (req.status == 200) {
            data = JSON.parse(req.response);
            if (data != null && data.value.length > 0) {
                console.log(data.value);
            }
        }
        else {
            var error = JSON.parse(req.response).error;
            console.log(error.message);
        }
    }

    pastedimage1565319189973v2.png

    Regards,

    Clofly

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans