Monday, February 6, 2017

Show CRM entity form to particular Business unit users only

In MS CRM we can enable security role to custom forms, and only selected role users can view that form. When selecting role, all Roles are shown form ROOT business unit, there is no option to get security role from child business units.

In some cases if you want to show custom entity form only for particular business unit users regardless of their role, then need to write custom JavaScript code.

Add following function for entity form, which want to show based on business unit, if users business unit is not allowing to view form, then user will be redirected to other form.

var accountScript = {
    showFormBasedOnBusinessUnit: function () {
        var userId = Xrm.Page.context.getUserId();
        userId = userId.replace("{", "").replace("}", "");
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/systemusers(" + userId + ")?$select=_businessunitid_value", false);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(this.response);
                    var businessunitid = result["_businessunitid_value"];
                    var businessunitidname = result["_businessunitid_value@OData.Community.Display.V1.FormattedValue"];
                   
                    if (businessunitidname != "Finance") {
                        var forms = Xrm.Page.ui.formSelector.items.get();
                        for (var i in forms) {
                            var formname = forms[i].getLabel();
                            if (formname == "Information") {
                                forms[i].navigate();
                                break;
                            }
                        }
                    }

                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
    }

};


37 comments:

  1. Hi Mahadeo Matre,
    In CRM 2015 i want to set lookup style as multi for selecting multiple records at a time. When i use following code it is not working
    document.getElementById("schemaname").atrributes('lookupstyle','multi')
    i am not able to found element itself in the DOM by using document.getElementById

    ReplyDelete
    Replies

    1. IEEE Final Year projects Project Center in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. <Final Year Projects for CSE It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, project projects for cseAngular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. "Customized CRM Software Solution" and "CRM Applications Development Services India For Your Business" - Hire the expert custom CRM software developers for your crucial projects. Our highly motivated professionals are ready to serve you 24*7.

    ReplyDelete
  3. Sunbridge Software Solutions Pvt. Ltd. Is a Microsot Dynamics 365 service provider from Pune and India. Apart from providing the perfect software for your company, we also offer software implementation, support and training.

    ReplyDelete
  4. This article is more useful for how to relationship with the customer and
    maintain the software.
    crm system

    ReplyDelete
  5. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up Salesforce Online Training Bangalore

    ReplyDelete
  6. You’re amazing man. You give super and super always.Mitsubishi laser parts
    Thanks for introducing these idea to us.

    ReplyDelete
  7. How you are going when you using zoho platform or others? Than code is same for java scripts

    ReplyDelete
  8. Thank you for sharing this post
    Very nice post here thanks for it I always like and search such topics and everything connected to them.
    CRM For Real Estate Industry

    ReplyDelete
  9. This is really interesting, you’re a very skilled blogger.
    I have bookmarked this article page as I received good information from this.

    Best CRM Software in Hyderabad | Best Project Management Software in Hyderabad

    Best ERP Software in India | Cloud CRM Software in Hyderabad

    ReplyDelete
  10. Thanks for sharing an informative post, If you wants to know about CRM system This is the right place for you.

    ReplyDelete
  11. The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog
    crm solutions

    ReplyDelete
  12. "Great blog, good information is given.It was worth reading.Thanks for posting the blog. IT Help Desk Software | Ticketing System | Apptivo Help Desk"

    ReplyDelete
  13. "Great blog, good information is given.It was worth reading.Thanks for posting the blog. IT Help Desk Software | Ticketing System | Apptivo Help Desk"

    ReplyDelete
  14. Really very great information for that post, am amazed and then more new information are get after refer that post. I like that post.
    CRM Software in Dubai
    CRM Software
    CRM Software in UAE
    Best CRM Software
    CRM Software for Small Business

    ReplyDelete
  15. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had
    CRM with Invoicing

    ReplyDelete
  16. Great Blog, there is so much reality written in this content and everything is something which is very hard to be argued. Top notch blog having excellent content. Custom solution development

    ReplyDelete
  17. Great post, Thanks for your efforts in sharing this post with us. This was really awesome. kindly keep continuing the great work. Custom solution development

    ReplyDelete
  18. I read your blog it's very nice and very helpful, I learn something new every time from this website, Thanks for sharing this information with us. I am also a blogger i guide people on App and Software Development. You can visit my blog here real estate software development

    ReplyDelete
  19. Share great information about your blog , Blog really helpful for us . We read your blog , share most useful information in blog . Thanks for share your blog here .
    top crm software

    ReplyDelete
  20. 1. I am very glad that I have come across such a beautifully designed article an full of fresh ideas and quality content
    Click for info



    ReplyDelete
  21. Nice Blog!! Thanks for sharing. CRM For Real Estate am very glad that I have come across such a beautifully designed article an full of fresh ideas and quality content
    click now

    ReplyDelete