Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to get Selected View Id using javscript in List Page of any entity in UCI

Posted on by 10

Hi All,

currently i am using "Xrm._page.getUrl()" for get viewID but i am getting error. please see given below error.

For get selected view id i am using this code.

var urlParams = new URLSearchParams(Xrm._page.getUrl());
var viewId = urlParams.get("viewid").replace("{", "").replace("}", "");

but it's not working well.

please suggest best solution.

pastedimage1601288040049v1.png

  

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Hi Altaf,

    It is very glad that your problem has been solved.

    If you had found any answer helped, please kindly mark it as verified to close the thread, it would be really appreciated.

    Regards,

    Clofly

  • Altaf Taqvi Profile Picture
    Altaf Taqvi 10 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Yes, parent.window.location.href is working well, thanks for support

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Hi,

    I have tried my CRM UCI instance and it works. See below image.

    4478.CQ18.PNG

    I have tried in Chrome and IE and it works.

    Please mark my answer verified if i were helpful

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Hi Altaf,

    Have you checked URL when executing the code?

    Make sure you can get the full URL with parameters.

    company.crm.dynamics.com/main.aspx?appid=0cf394ae-3dcb-ea11-a812-000d3aa08b45&pagetype=entitylist&etn=contact&viewid=b28063f8-a032-40ce-9f9b-d8912372c534&viewType=1039

    Regards,

    Clofly

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Hi Altaf,

    Have you checked whether "viewid" parameter exists in URL?

    Or did you run the code in console directly? For example, if we run it in a web resource, such as performing the function in a ribbon button, then location.href might be different.

    If you are running it in ribbon button, try to use parent.window.location.href instead to check whether it is able to get real full URL.

    In a word, please check the actual value of location.href.

    In addition, you could also try capturing the viewid with pure javascript function.

    var viewid = getParameterByName("viewid");
    
    console.log(viewId);
    
    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, '\\$&');
        var regex = new RegExp('[?&]'   name   '(=([^]*)|&|#|$)'),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\ /g, ' '));
    }
     

    pastedimage1601351501505v1.png

    Regards,

    Clofly

  • Altaf Taqvi Profile Picture
    Altaf Taqvi 10 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Can someone help me fixing this issue in Unified interface?

  • Altaf Taqvi Profile Picture
    Altaf Taqvi 10 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    it's also not working.

    2262.Untitled2.png

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    Hi Altaf,

    Xrm.Page is deprecated, we should use the replacement function to get organization URL.

    https://pradipwebmaster.wordpress.com/2018/11/20/how-to-replace-xrm-page-context-getclienturl-in-dynamics-365-version-9/

    However, currently client API only provides function that return the organization URL, like company.crm.dynamics.com.

    To access to parameters of URL, we need to use location object directly.

    var urlParams = new URLSearchParams(location.href);
    var viewId = urlParams.get("viewid").replace("{", "").replace("}", "");
    console.log(viewId);
    
    

    8688.JPG

    Regards,

    Clofly

  • Altaf Taqvi Profile Picture
    Altaf Taqvi 10 on at
    RE: How to get Selected View Id using javscript in List Page of any entity in UCI

    anyone can suggest best solution for this error as it's necessary for me

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans