Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

FetchXml

Posted on by 218

I want to get the value of manager of the current user and use that value in fetchxml to create a view based on manager of the current user. How can I do that??

*This post is locked for comments

  • Aparna1 Profile Picture
    Aparna1 218 on at
    RE: FetchXml

    Hi Alex,

    correct I need this type of filter using fetchXML. Can You please suggest any solution?

    Thanks

    Aparna

  • Aparna1 Profile Picture
    Aparna1 218 on at
    RE: FetchXml

    Thank you so much Hemant. But the solution provided by you can be used in javascript. I want to use value of "var fetchXml" in the same FetchXML for filter.

     I need to have a view like this: 

    30511.1.PNG

    this manager value will be dynamic.

    Thanks

    Aparna

  • Verified answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXml

    Hi Aprna,

    Here is the sample code in JavaScript, this give an idea:

    function getManager() {

       var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

           "<entity name='systemuser'>" +

           "<attribute name='systemuserid' />" +

           "<attribute name='parentsystemuserid' />" + //manager

           "<filter type='and'>" +

           "<condition attribute='systemuserid' operator='eq-userid' />" +

           "</filter>" +

           "</entity>" +

           "</fetch> ";

       var encodedFetchXml = encodeURI(fetchXml);

       var queryPath = "/api/data/v8.0/accounts?fetchXml=" + encodedFetchXml;

       var requestPath = Xrm.Page.context.getClientUrl() + queryPath;

       var req = new XMLHttpRequest();

       req.open("GET", requestPath, true);

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

       req.onreadystatechange = function () {

           if (this.readyState === 4) {

               this.onreadystatechange = null;

               if (this.status === 200) {

                   var returned = JSON.parse(this.responseText);

                   var results = returned.value;

                   if (results.length > 0) {

                       var managerId = results[0]["_parentsystemuserid_value"];

                       //TODO: Implement logic for handling results as desired

                   }

               } else {

                   alert(this.statusText);

               }

           }

       };

       req.send();

    }

    for more details you may use the below link:

    www.hbs.net/.../using-fetchxml-in-web-api-queries-via-javascript-f

    Thanks

    Hemant

  • Aparna1 Profile Picture
    Aparna1 218 on at
    RE: FetchXml

    Hi Hemant,

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

    <entity name="systemuser">

    <attribute name="systemuserid" />

    <attribute name="parentsystemuserid" />//manager

    <filter type="and">

    <condition attribute="systemuserid" operator="eq-userid" />

    </filter>

    </entity>

    </fetch>  

    in this code we retrieved "parentsystemuserid". I want to store this value in a variable and use it later in filter criteria as a dynamic variable value. how can I do that?

    Thanks

    Aparna

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXml

    Sure Aparna,

    Could you please share your code in detail?

    Thanks

    Hemant

  • Aparna1 Profile Picture
    Aparna1 218 on at
    RE: FetchXml

    Hi Hemant,

    I am new to fetchXML. Can you please tell me how can I use this manager value? How can I store this value to a variable?

    Thanks

    Aparna

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXml

    Hi Aparna,

    I guess its data issue, that guide(manager) which is present in the source and not available in the target.

    Please have a look  here..it may helps you

    daxsnippets.wordpress.com/.../dependency-calculation-error

    Hemant

  • Aparna1 Profile Picture
    Aparna1 218 on at
    RE: FetchXml

    Thanks Hemant.

    I made the changes in xml file under saved Queries section and made zip solution.

    Now when I am trying to import it as a solution it is showing me error as:

    "Message There was an error calculating dependencies for this component.  Error in saved query with id {0}".

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: FetchXml

    Hi,

      wondering if you need this kind of filter:

    30511.1.PNG

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    Hemant Kumar Sahu 1,825 on at
    RE: FetchXml

    Hi Aparna,

    The below fetchxml will give you the manager of the current user.

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="systemuser">
    <attribute name="systemuserid" />
    <attribute name="parentsystemuserid" />//manager
    <filter type="and">
    <condition attribute="systemuserid" operator="eq-userid" />
    </filter>
    </entity>
    </fetch>


    "use that value in fetchxml to create a view based on manager of the current user"

    Do you want to create a view dynamically?

    If yes, please go through the below url, this may help you

    community.dynamics.com/.../how-to-create-crm-entity-view-programmatically

    community.dynamics.com/.../158168

    Thanks
    Hemant

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans