web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving Attributes from Multiple Linked Entity

(0) ShareShare
ReportReport
Posted on by 910

Dear Experts,

I have the following requirement.

Scenario: A user wants to create a task which is regarding to an opportunity, the opportunity is linked to a custom entity called management team. The management team has a field which is a lookup field called "Team Member" which is related to user entity.

Now i want to check whether the user who is creating the task for the opportunity is a part of the management team in the opportunity. If yes then the user is allowed to move on and save the task, otherwise the user should be prompted and not allowed to create a task for that opportunity. i cannot do this from a security roles because the user is not the owner or creator of the opportunity but is a part of the opportunity which is linked with a custom entity as mentioned above.

I am looking for a solution with javascript, i have done this before with 2 linked entities for example i can get values from the linked opportunities, but how can i access the management team (Custom Entity) attributes from the task form as they are not linked directly but rather from the opportunity entity.

If i could access the user in the custom entity i can compare the creator of the task with the team member of the custom entity.

Please provide a solution.

*This post is locked for comments

I have the same question (0)
  • Stef Rose Profile Picture
    240 on at

    First, be sure that whenever a user creates a task over CRM deployment, he becomes a point of reference for that workflow or task, and he his by default regardless to the Custom entity called Team Management and regardless to attributes given by user_account. I suggest you to let system_defaults for users_accounts because of all the schemes invoked by system_Entities related to workflow tasking and, in the case you have self created a custom entity, use the native components used to define standard CRM Deployment Entity under MS Visual Studio Deployment. You will be granted of such way for working.

    Have a nice day!

  • Ahmed Zaveri Profile Picture
    910 on at

    Im unable to understand a single word you have written, i was just asking for a solution with javascript or any other tool, can you provide an example for this.

  • Stef Rose Profile Picture
    240 on at

    If you cannot understand basic Microsoft programming as which language to use with what type of products, you should not program anymore. Think before asking question as can I use JavaScript for CRM Deployment editing. Remember that I take time to answer your question, and will surely not give you all the answer for free and without thinking from you.

  • Ahmed Zaveri Profile Picture
    910 on at

    I would suggest you to first understand the question and then try to answer it and stop wasting others time.  If you dont answer for free then stop answer the questions which dont have any idea and just show off that you are a champion and make other feel stupid, which by the way is not the case here.

    So please dont reply to me anymore and let some real expert answer this question.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    So I'm assuming that you've already got the code to run fetchxml from Javascript (using something like xrmsvctoolkit.codeplex.com) - is the issue that you are after the syntax for multiple levels of linked entities? Advanced find of course only allows you to return results for one level of linked entities - and useing 'Download FetchXml' it's a good starting point. 

    link-entities can be added and nested multiple levels deep. Here is a an example of a nested link-entity:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="account">
    <attribute name="ownerid" />
    <order attribute="name" descending="false" />
    <filter type="and">
    <condition attribute="ownerid" operator="eq-userid" />
    </filter>
    <link-entity name="account" from="accountid" to="parentaccountid" link-type="outer" alias="a1">
    <attribute name="ownerid" />
    <link-entity name="account" from="accountid" to="parentaccountid" link-type="outer" alias="a2">
    <attribute name="ownerid" />
    </link-entity>
    </link-entity>
    </entity>
    </fetch>

    When you execute the fetch, the alias attribute is the key to getting the values from the linked entities - each attribute will be returned as <alias>.<attribute name>

    So by using this nesting of link-entities, you can then get to your Management Team entity.

    hth

  • Ahmed Zaveri Profile Picture
    910 on at

    Hello Scott,

    First of all thanks for understanding my requirement.

    Secondly, i am very weak at programming most of the time have worked for out of the box customization and a little bit of JS here and there from examples.

    So here is the thing, yes i have done this before but my requirement was different. I linked the service activity with task and i was trying to set the regarding of service activity equal to the task regarding which i was sucessful by using the following code which i got from the web.

    // Only make changes to this function; you may add this function to Form Onload Event,

    // Field OnChange events etc.

    function GetDetails() {

       var EntityName, EntityId, AccountNumber, AccountEmailAddress, LookupFieldObject;

       var PrimaryContactLookupId, PrimaryContactLookupName, PrimaryContactLookupType;

       var resultXml;

       LookupFieldObject = Xrm.Page.data.entity.attributes.get('parentcustomerid');

       // If lookup field has value then the code will only run

       if (LookupFieldObject.getValue() != null) {

           //Fetch and place Entity Id (GUID) and Name (String) form lookup field into local variables

           EntityId = LookupFieldObject.getValue()[0].id;

           EntityName = LookupFieldObject.getValue()[0].entityType;

           // Paramter explaination for function call  

           // RetrieveEntityById('account', AccountId, 'accountnumber,emailaddress1');

           // 1st paramter requires entity name (not display or schema name) just pass it in a string  

           // i.e. for Account entity use 'account' for opportunity entity use 'opportunity'

           // 2nd paramter requires entity Id (GUID Type) field which we have retrieved and stored in  

           // AccountId local variable

           // 3rd paramter requires attributes to be retrieved schema name, if thrid attributed is  

           // required to be retrieved then use like: i.e. 'accountnumber,emailaddress1,telephone2'

           resultXml = RetrieveEntityById(EntityName, EntityId, 'accountnumber,emailaddress1,primarycontactid');

           // In retrieved XML document check if it has accountnumber attribute  

           if (resultXml != null && resultXml.selectSingleNode('//q1:accountnumber') != null) {

               // If XML document has account number attribute then assign to local variable AccountNumber

               AccountNumber = resultXml.selectSingleNode('//q1:accountnumber').nodeTypedValue;

               //Display Account Number Value in a Message Box

               alert("Account Number :" + AccountNumber);

               //If required then use the below code line to set value in field on form  

               //Xrm.Page.data.entity.attributes.get('new_myaccountnumber').setValue(AccountNumber);

           }

           // In retrieved XML document check if it has emailaddress1 attribute  

           if (resultXml != null && resultXml.selectSingleNode('//q1:emailaddress1') != null) {

               // If XML document has account number attribute then assign to local variable AccountEmailAddress

               AccountEmailAddress = resultXml.selectSingleNode('//q1:emailaddress1').nodeTypedValue;

               alert("Email Address :" + AccountEmailAddress);

               //If required then use the below code line to set value in field on form  

               //Xrm.Page.data.entity.attributes.get('new_myemailaddress').setValue(AccountEmailAddress);

           }

             // In retrieved XML document check if it has primarycontactid lookup attribute  

           if (resultXml != null && resultXml.selectSingleNode('//q1:primarycontactid') != null) {

               // If XML document has primarycontactid lookup attribute then assign to local variable  

               PrimaryContactLookupId = resultXml.selectSingleNode('//q1:primarycontactid').nodeTypedValue;

               // If XML document has primarycontactid lookup attribute then assign to local variable  

               PrimaryContactLookupName = resultXml.selectSingleNode('//q1:primarycontactid').getAttribute("name");

               // If XML document has primarycontactid lookup attribute then assign to local variable  

               PrimaryContactLookupType = resultXml.selectSingleNode('//q1:primarycontactid').getAttribute("type") ;

               alert("Primary Contact Lookup Id :" + PrimaryContactLookupId);

               alert("Primary Contact Lookup Name :" + PrimaryContactLookupName);

               alert("Primary Contact Lookup Type :" + PrimaryContactLookupType);

           }        

       }

    }

    // Do not make any changes to this function

    function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {

       var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;

       arrayEntityColumns = prmEntityColumns.split(",");

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

           xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";

       }

       var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

       //Prepare the SOAP message.

       var xml = "<?xml version='1.0' encoding='utf-8'?>" +

       "<soap:Envelope xmlns:soap='schemas.xmlsoap.org/.../& +

       " xmlns:xsi='www.w3.org/.../XMLSchema-instance& +

       " xmlns:xsd='www.w3.org/.../XMLSchema& +

       authenticationHeader +

       "<soap:Body>" +

       "<Retrieve xmlns='schemas.microsoft.com/.../WebServices& +

       "<entityName>" + prmEntityName + "</entityName>" +

       "<id>" + prmEntityId + "</id>" +

       "<columnSet xmlns:q1='schemas.microsoft.com/.../Query& xsi:type='q1:ColumnSet'>" +

       "<q1:Attributes>" +

       xmlEntityColumns +

      "</q1:Attributes>" +

       "</columnSet>" +

       "</Retrieve></soap:Body></soap:Envelope>";

       //call function to create Soap Request to ms crm webservice

       xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

       xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);

       xmlHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Retrieve");

       xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

       xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

       xmlHttpRequest.send(xml);

       resultXml = xmlHttpRequest.responseXML;

       var errorCount = resultXml.selectNodes('//error').length;

       if (errorCount != 0) {

           var msg = resultXml.selectSingleNode('//description').nodeTypedValue;

           alert("Error Message : " + msg);

       }

       else {

           return resultXml;

       }

    }

    Now with this code i was able to get the regarding field of the related task entity. But now my requirement is even more complex, as my management team entity (custom entity) is a sub-grid in my opportunity form instead of a look-up field. Secondly, the management team can i have multiple records, can be 3 or 4 or 5 records.

    Now if you could tell me that is it still possible with javascript or many of the experts have told me that you require plug-ins for the following requirement. In either case, can you suggest some examples as i have no idea for javascript or plug-ins.

    I would highly appreciate your help in this case.

    Thanking you in Anticipation.

    Ahmed Zaveri

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans