Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer Service forum

Map a related entity on load of the form

(0) ShareShare
ReportReport
Posted on by 5

Good Morning,

I have a Dynamics 365 Portal from within the portal the user navigates to their profile page, on load of the profile page I need to load a related record in a look up instead of the user simply clicking on the lookup, the related record should essentially Map to the lookup.

The question is, is it possible to load the related record into the lookup onload of the form using a liquid statement or JavaScript?

You assistance would be greatly appreciated.

Regards,

Margaret Testa

showbox

Categories:
  • cloflyMao Profile Picture
    25,208 on at
    RE: Map a related entity on load of the form

    Hi Margaret,

    Is your profile page means below ?

    4452.x001.PNG

    If so, that depends on what your environment is.

    If your enviro is OP, then you could access the aspx page and add liquid statement on the page.

    If your enviro is Online, you may had found that the profile page source code is not accessible because its page type is Rewrite type(some specific pages in ADX portal) compared with Web Template type,

    thus we couldn't write code directly on the profile page.

    Here is my workaround, you could take it as reference:

    1. Create an Entity List for your lookup related entity, then enable its OData Feed option,

    it will create a public accessible dataset for your specifc entity, just like Web API, and the result is based on the selected View criteria.

    x002.PNG

    Please read following article for how it works:

    https://community.dynamics.com/crm/b/crminogic/posts/retrieve-dynamics-365-crm-data-in-portal-by-calling-odata-using-javascript

    2. Create a global js function to detect whether the current page is Profile page,

    for me, I add the detection function in Header web template, because its a global web page, 

    our function will be fired when the path contains Profile.

    3. Hide default lookup button, and call the previous OData dataset with Ajax,

    render result on page.

    4. Set the lookup field value with function below, its similar to set lookup field value in CRM.

    $('#logicalname').attr('value', id);
    $('#logicalname_name').attr('value', name);
    $('#logicalname_entityname').attr('value', entityName);

    5. Full code:

    var path = location.pathname;

    if (path.indexOf('profile') > -1) {

    var url = "../_odata/openAccounts";

    $.ajax({
    type: "GET",
    url: url,
    dataType: 'json'
    }).done(function(json) {

    $('fieldset:eq(1)').after('<div id="accountlist"></div>');

    $('.launchentitylookup').hide();

    for (var i = 0; i < json.value.length; i++) {
    $('#accountlist').append('<div data-id=' + json.value[i].accountid + ' class="account-item">' + json.value[i].name + '</div>');
    }

    $(".account-item").css({ "border": "1px solid black", "padding": "15px" });

    $(".account-item").on('click', function() {
    var id = $(this).attr('data-id');
    var name = $(this).text();
    var entityName = 'account';
    $('#parentcustomerid').attr('value', id);
    $('#parentcustomerid_name').attr('value', name);
    $('#parentcustomerid_entityname').attr('value', entityName);
    })

    })

    }

    6. It seems that there is no jQuery library on Profile page, we could add it in Header source code.

    x003.PNG

    7. Final result:

    your user could only select rendered list item

    x004.PNG

    Note:

    1. You may need to pagination the result.

    2. You may need to make customization CSS for rendered result.

    3. Full logic should be completed with JS.

    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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard > Customer Service

Featured topics

Product updates

Dynamics 365 release plans