Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / List the users the opp...
Sales forum
Answered

List the users the opportunity is shared with

Posted on by 448

Hi all

I need to have the list of users with whom the opportunity is shared (table PrincipalObjectAccess).

I think to make this with power automate, but I've not idea how to ... 

Thanks in advance for any help or Idea.

  • Verified answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: List the users the opportunity is shared with

    Hi DiePic,

    You can follow below steps.

    1. In the list rows action, set table name as custom value,

    pastedimage1677060880556v1.png

    2. Type table name as principalobjectaccessset

    3.Fetch Query paste following query and replace opportunity id with you opportunity id as static or dynamic value.

    <fetch distinct="true">
    <entity name="principalobjectaccess">
    <attribute name="principalobjectaccessid" />
    <filter>
    <condition attribute="principaltypecode" operator="eq" value="8" />
    <condition attribute="objectid" operator="eq" value="9d3d18ff-5104-4173-9ed5-b1805793eea4" />
    </filter>
    <link-entity name="opportunity" from="opportunityid" to="objectid" link-type="inner" alias="opportunity">
    <attribute name="name" />
    </link-entity>
    <link-entity name="systemuser" from="systemuserid" to="principalid" link-type="inner" alias="user">
    <attribute name="fullname" />
    </link-entity>
    </entity>
    </fetch>

    4. Final action will look like this.

    pastedimage1677061065122v2.png

    Cheers,

    Ketan

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Moderator on at
    RE: List the users the opportunity is shared with

    Hi DIE PIC,

    I do not think you can do it with Power Automate as the List rows action of dataverse is not showing the PrincipalObjectAccess.

    pastedimage1677055958083v1.png

    I have done it with the help of JS. Here is the code:

    // A namespace defined for the sample code
    // As a best practice, you should always define
    // a unique namespace for your libraries
    var Test = window.Test || {};
    (function () {
    // Define some global variables
    let entitysPluralName = {
    PrincipalObjectAccesss: "principalobjectaccessset"
    };
    let globalVariables = {
    Results: "",
    WebAPIVersion: "v9.1"
    };

    this.retrievePrincipalObjectAccess = function () {
    try {
    var fetchData = {
    opportunityid: this.getId()
    };
    var fetchXmlQuery = [
    "<fetch>",
    " <entity name='principalobjectaccess'>",
    " <attribute name='principaltypecode' />",
    " <attribute name='principalobjectaccessid' />",
    " <attribute name='principalid' />",
    " <link-entity name='opportunity' from='ecs_expenseid' to='objectid'>",
    " <filter type='and'>",
    " <condition attribute='opportunityid' operator='eq' value='", fetchData.opportunityid, "'/>",
    " </filter>",
    " </link-entity>",
    " </entity>",
    "</fetch>",
    ].join("");
    this.retrieve(globalVariables.WebAPIVersion, entitysPluralName.PrincipalObjectAccesss, fetchXmlQuery);
    if (globalVariables.Results.length > 0) {
    //your logic
    }
    }
    catch (e) {
    this.openAlertDialog("Error from getId: " + "e: " + e + ". e.mesage: " + e.message);
    }
    }

    this.retrieve = function (webAPIVersion, entitysPluralName, fetchXmlQuery) {
    try {
    var req = new XMLHttpRequest();
    req.open(
    "GET",
    parent.Xrm.Page.context.getClientUrl() +
    "/api/data/" + webAPIVersion + "/" + entitysPluralName + "?fetchXml=" +
    encodeURIComponent(fetchXmlQuery),
    false
    );//Sync
    req.setRequestHeader("Prefer", 'odata.include-annotations="*"');
    req.onreadystatechange = function () {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var results = JSON.parse(this.response);
    globalVariables.Results = results.value;
    } else {
    alert(this.statusText);
    }
    }
    };
    req.send();
    } catch (e) {
    this.openAlertDialog("Error from retrieve: " + "e: " + e + ". e.mesage: " + e.message);
    }
    }

    this.getId = function (formContext) {
    let iD = "";
    try {
    iD = formContext.data.entity.getId();
    } catch (e) {
    this.openAlertDialog("Error from getId: " + "e: " + e + ". e.mesage: " + e.message);
    }
    return iD;
    }

    this.openAlertDialog = function (alertStrings) {
    try {
    Xrm.Navigation.openAlertDialog(alertStrings).then();
    } catch (e) {
    Xrm.Navigation.openAlertDialog("Error from openAlertDialog: " + "e: " + e + ". e.mesage: " + e.message).then();
    }
    }
    }).call(Test);

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,263 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,112 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans