locked
Using JavaScript on a Quick Create form to determine where it was launched (2013) RRS feed

  • Question

  • Using JavaScript I would like to determine where the User was when they launched a Quick Create form.

    I just need to be able to identify that original or parent form.

    Why? Well, a contextual feedback solution using quick create - add a new entity "Help Feedback" enable it for Quick Create, allow the users to feedback via the Quick Create form, inferring context via Java Script (to save them entering that bit).


    Martin Miller - Auckland, New Zealand

    Monday, June 16, 2014 9:22 PM

Answers

  • Hi Martin,

    A bit of tweaking to my code will give you all 3 pieces of information.

    You'll still end up with the Entity Type Code, but it shouldn't be much of a stretch to use that to get the name of the entity.

    function getQuickCreateContext() {
        var parentEtc = -1;
        var isRecord = false;
        var recordGuid = "";
        var sitemapPath = "";
    
        var contentPanel = parent.document.getElementById("crmContentPanel");
        if (contentPanel != null) {
            var parentSrc = contentPanel.getAttribute("src");
            if (parentSrc != null) {
                var firstSplit = parentSrc.split("etc=");
                if (firstSplit.length > 1) {
                    var secondSplit = firstSplit[1].split("&");
                    if (secondSplit.length > 1) {
                        var etc = secondSplit[0];
                        if (parseInt(etc) != "NaN") {
                            parentEtc = etc;
    
                            thirdSplit = secondSplit[1].split("id%3d%257b");
                            if (thirdSplit.length > 1) {
                                isRecord = true;
                                recordGuid = thirdSplit[1].split("%257d")[0];
                            }
                        }
                    }
                }
                var sitemmapSplit = parentSrc.split("sitemappath=");
                if (sitemmapSplit.length > 1) {
                    // Get the friendly sitemap path name
                    sitemapPath = sitemmapSplit[1].replace(/%7c/g, " ");
                }
            }
        }
    }

    This returns you with 4 pieces of information, which should give you a comprehensive idea of where the user is in the system.

    What you do with this information is up to you. :)

    If you need any more help with this, let me know.

    ~ Atomic Coder

    Tuesday, June 17, 2014 9:54 PM

All replies

  • Hi Martin,

    I suspect you are only going to find unsupported ways of doing this without changing your requirements.

    The following (unsupported) method works from both forms and views and will return the Entity Type Code of the parent entity.

    function getParentEtc() {
        var contentPanel = parent.document.getElementById("crmContentPanel");
        if (contentPanel != null) {
            var parentSrc = contentPanel.getAttribute("src");
            if (parentSrc != null) {
                var firstSplit = parentSrc.split("etc=");
                if (firstSplit.length > 1) {
                    var parentEtc = firstSplit[1].split("&")[0];
                    if (parseInt(parentEtc) != "NaN") {
                        // Do something with your Entity Type Code value
                        // This can easily be referenced in a plugin to determin the entity name etc
                    }
                }
            }
        }
    }

    Let me know if you need any additional help on what to do with the Entity Type Code once you have it. :)

    ~ Atomic Coder

    Tuesday, June 17, 2014 1:59 AM
  • Thanks for the reply.

    Ideally what I am hoping to get is

    • 'Parent window' Form (name and/or GUID)
    • 'Parent window' Entity
    • Record GUID for the record shown on the 'parent window', however for a view this is kind of inapplicable.

    Martin Miller - Auckland, New Zealand

    Tuesday, June 17, 2014 2:13 AM
  • Hi Martin,

    Are you expecting users to give feedback on specific records, and not just an entity in general?

    ~ Atomic Coder

    Tuesday, June 17, 2014 2:35 AM
  • No, its just context.

    Martin Miller - Auckland, New Zealand

    Tuesday, June 17, 2014 2:37 AM
  • Hi Martin,

    Just to make sure I understand your requirements, you wish to know the Entity, Form Name (as there can be multiple forms for 1 entity), and record guid (if applicable) from the context of where they open the quick create form?

    ~ Atomic Coder

    Tuesday, June 17, 2014 4:54 AM
  • I want to determine the context of where the Quick Create was drawn i.e. the main form or view behind, plus the entity, and if possible the record guid.

    So I am not sure the fact that an entity has multiple forms is relevant unless they are simultaneously drawn on screen.


    Martin Miller - Auckland, New Zealand

    Tuesday, June 17, 2014 9:10 PM
  • Hi Martin,

    A bit of tweaking to my code will give you all 3 pieces of information.

    You'll still end up with the Entity Type Code, but it shouldn't be much of a stretch to use that to get the name of the entity.

    function getQuickCreateContext() {
        var parentEtc = -1;
        var isRecord = false;
        var recordGuid = "";
        var sitemapPath = "";
    
        var contentPanel = parent.document.getElementById("crmContentPanel");
        if (contentPanel != null) {
            var parentSrc = contentPanel.getAttribute("src");
            if (parentSrc != null) {
                var firstSplit = parentSrc.split("etc=");
                if (firstSplit.length > 1) {
                    var secondSplit = firstSplit[1].split("&");
                    if (secondSplit.length > 1) {
                        var etc = secondSplit[0];
                        if (parseInt(etc) != "NaN") {
                            parentEtc = etc;
    
                            thirdSplit = secondSplit[1].split("id%3d%257b");
                            if (thirdSplit.length > 1) {
                                isRecord = true;
                                recordGuid = thirdSplit[1].split("%257d")[0];
                            }
                        }
                    }
                }
                var sitemmapSplit = parentSrc.split("sitemappath=");
                if (sitemmapSplit.length > 1) {
                    // Get the friendly sitemap path name
                    sitemapPath = sitemmapSplit[1].replace(/%7c/g, " ");
                }
            }
        }
    }

    This returns you with 4 pieces of information, which should give you a comprehensive idea of where the user is in the system.

    What you do with this information is up to you. :)

    If you need any more help with this, let me know.

    ~ Atomic Coder

    Tuesday, June 17, 2014 9:54 PM