locked
How to check client from the javascript code RRS feed

  • Question

  • Hello All,

    i have come across a requirement where there is trouble to check whether the client is browser or outlook.

    kindly help me in resolving this.

    Monday, November 16, 2015 11:15 AM

All replies

  • Hello,

    context.client.getClient() will return you type of client.

    Recheck this article - https://msdn.microsoft.com/en-us/library/gg334511.aspx#BKMK_Client


    Dynamics CRM MVP
    My blog

    Monday, November 16, 2015 11:25 AM
    Moderator
  • Hello,

    context.client.getClient() will return you type of client.

    Recheck this article - https://msdn.microsoft.com/en-us/library/gg334511.aspx#BKMK_Client


    Dynamics CRM MVP
    My blog

    The context.client.getClient() is throwing the error as context is undefined.

    how to resolve that

    Monday, November 16, 2015 12:07 PM
  •  <script type="text/javascript">
             function ShowContact() {

                 var _hdnWebsitePath = document.getElementById('hdnWebsitePath').value;
                 if (typeof Xrm !== 'undefined') {
                     window.parent.Xrm.Utility.openEntityForm("contact");
                 }
                 else {
                     window.open(_hdnWebsitePath + '/main.aspx?etn=contact&pagetype=entityrecord');
                 }
             }
        </script>

    The above is the script of which the else part i want to check for the client is web or outlook.

    Monday, November 16, 2015 12:24 PM
  • Hello,

    Getting of the context is depends on type of page you use this script:

    1. In case this is usual CRM Page you can use following code to get context:

    var context = Xrm.Page.context;

    2. In case this is your webresource you will have to use GetGlobalContext function to get context like:

    var context = GetGlobalContext();

    to get this function you  will need to include reference to ClientGlobalContext.js.aspx page to references. Recheck this article - https://msdn.microsoft.com/ru-ru/library/gg328541.aspx?f=255&MSPPError=-2147217396#BKMK_ClientGlobalContext_js_aspx


    Dynamics CRM MVP
    My blog

    Monday, November 16, 2015 12:52 PM
    Moderator
  • Thanks for your valuable time on this Andrii Butenko.

    But in my case it is a custom web page that is having button and on clicking of that button the javascripts gets called .

    on such type of scenario how can i proceed further.

    Monday, November 16, 2015 1:09 PM
  • So webpage means html webresource then follow point 2 I described in previous reply.

    Dynamics CRM MVP
    My blog

    Monday, November 16, 2015 1:19 PM
    Moderator
  • Thanks for the update Andrii Butenko .

    In my case webpage means .ASPX page and not the HTML webresource.

    Kindly suggest me the alternate option on this.


    Tuesday, November 17, 2015 10:34 AM
  • Please provide scenario you try to implement and what you've done already to do it?

    Dynamics CRM MVP
    My blog

    Tuesday, November 17, 2015 12:33 PM
    Moderator
  • Hello All,

    I have a scenario where there is a custom .aspx page ,on this cutome page there is button and that button opens the crm contact entity form.

    i have write a javascript to open the crm entity form .

    my problem is how to get the context of crm from the custom button .

    Below is my javascript code.

    <script type="text/javascript">
    function ShowContact() {

    var _hdnWebsitePath = document.getElementById('hdnWebsitePath').value;
    if (typeof Xrm !== 'undefined') {
    window.parent.Xrm.Utility.openEntityForm("contact");
    }
    else {
    window.open(_hdnWebsitePath + '/main.aspx?etn=contact&pagetype=entityrecord');
    }
    }
    </script>

    where _hdnWebsitePath  is the server path variable.

    Tuesday, November 17, 2015 12:57 PM
  • Please don't create any threads that duplicate one another.

    Dynamics CRM MVP
    My blog

    Tuesday, November 17, 2015 2:02 PM
    Moderator
  • Sorry if it seems duplicate but as you said show the scenario thats why i have type the script here.

    The scenario is simple .

    i have custom web page (.aspx page) not only single but more than 10.

    i have publish a website and made a separate virtual directory and publish the site in the iis.

    this website is on different port.

    i have made some custom navigation on sitemap and clicking on tile , i have  open this .aspx page.

    Now as this is the custom web page and in the web client it is under the main frame of the MSCRM, so the above sripts works correctly.

    this script is on click of the button on the custom web page.

    Problem.

    When the same thing we loads into the outlook client then it does not work.

    does not work means it redirects to the web client . But in the web client untill we log in first time the session is not maintained, so from the outlook client it opens the webpage but first time it redirects to the login page.

    My requirement is that it should not redirect to the login page into the web client but it should open contact entity form.

    so how to handle this type of situation from the outlook client.

    I believe that i am able to put the exact scenario .

    Kindly suggest me how to resolve this issue.

    Friday, November 20, 2015 6:02 AM
  • Hello,

    My suggestion is pretty simple. Use html/js/css webresources of CRM instead of using custom portal.


    Dynamics CRM MVP
    My blog

    Friday, November 20, 2015 12:04 PM
    Moderator
  • Thanks Andrii For your suggestion.

    But trouble is that we have codebehind of the .aspx page which is almost doing so many works like searching into the database and bringing the data that page we can not remove Now that is not possible.

    But can you give me the idea how to open the crm page from within the outlook client.

    do we have any javascript or any mechanism to open the outlook page.

    Monday, November 23, 2015 5:21 AM
  • I suggested the best way out. Now this is your turn - follow my suggestion and solve issue with 100% guarantee or not follow and scratch your head trying to fix SSO thing. Good luck.

    Dynamics CRM MVP
    My blog

    Monday, November 23, 2015 11:41 AM
    Moderator