RSS

Tag Archives: WebResource

CRM 2013 Open Entity Form in new Window by JavaScript

Introduction

During our customization in CRM, we need to open one Entity Form by JavaScript in a new Window.

Problem

By using Xrm.Utility.openEntityForm, it opens the record page in the same page or opens the record in a new Form.

Solution

To open the record in the new Window or to open in a new Dialog, we can use the following code

Note: Please give the Logical Name as Record Type is not taken in CRM 2013

function OpenRecords(Record_Id, Logical_Name_Of_Entity) {
    var reletivePath = "main.aspx?etn=" + Logical_Name_Of_Entity;
    reletivePath = reletivePath + "&pagetype=entityrecord&id=";

    var height = 1300; // Height of the Record Page.
    var width = 900; // Width of the Record Page.
    var windowName = "_blank";
    var serverUrl = Xrm.Page.context.getServerUrl();
    var nAgt = navigator.userAgent;

    if (serverUrl != null && serverUrl != "" 
                      && 
        Record_Id.replace("{", "").replace("}", "") != null)
    {
        serverUrl = serverUrl + reletivePath;
        serverUrl = serverUrl + Record_Id.replace("{", "").replace("}", "");
         
        if (nAgt.indexOf("Firefox") != -1) {
            window.open(serverUrl);
        } else {
            OpenStdWin(serverUrl, 
                       null, 
                       height, 
                       width, 
                       "titlebar=yes, resizable=yes");
        }
    }
}

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , , ,

Open Dialog box like CRM 2013

Introduction

In this Blog, we will explore how to open a Dialog Box similar with CRM 2013 look and feel.

Background

Sometimes, we need to open the custom WebResource in a Dialog Box. But the Dialog Box should look like other Dialog Box in CRM 2013.

Custom Dialog Box

Solution

We can achieve this by one CRM function in the following way:

Note: Here, URL must be without Server URL.

For the Parent Window:

var DialogOption = new Xrm.DialogOptions;
DialogOption.width = <Height>; DialogOption.height = <width>;

Xrm.Internal.openDialog(<Relative_Url_of_the_Webresource>, 
                        DialogOption, 
                        null, null, 
                        CallbackFunction);

function CallbackFunction(returnValue){ }

In the Dialog Box, please include:

<script type="text/javascript" 
        src="../../../../../../webresources/ClientGlobalContext.js.aspx"></script>
/*This Might change according to the url*/

And

//Pass the return Value to the parent window
Mscrm.Utilities.setReturnValue(oReturn);

try {
    closeWindow(true);//Close the dialog box
}
catch (e) { }

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , ,

CRM 2013 – How to get Server URL in SOAP or REST ?

Introduction

This blog is simply explains the trick for getting the Server URL for SOAP Endpoint or REST Endpoint from the Context.

In CRM 2011

We were using following two lines of code to get Server URL.

var context = GetGlobalContext();
serverUrl = context.getServerUrl();

Now in CRM 2013

getClientUrl() will be supported instead of getServerUrl().

var context = GetGlobalContext();
clientUrl = context.getClientUrl();

By Anish Thakur
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
 

Tags: , , , , , , , , , , , , , , , , , , , ,

CRM 2013 – Field Level Notification

Introduction

In CRM 2011, there was no Out of Box Functionality to show client side notifications on the Entity. We have used JScripts functions to show alert messages using Web Resources. In CRM 2013, Microsoft has introduced some new methods to show notifications on client side.

Background

The requirement was, while entering data in an Account form, the Account Number must be greater than 4 digits, else we had to show a notification “The account number should be more than 4 digits” on the field level.

Code

We will use following two methods for our task.

  • setNotification(message) : To set the Notification near the field
  • clearNotification() : To remove the Notification from the field

Code can be used onChange or onSave event.

//Function To Set Notification On Field Level
function SetFieldNotification()
{
    //Get The Control
    var field = Xrm.Page.getControl("accountnumber");

    //Get The Count Of Digits In Acccount Number
    var numberOfDigit = CountDigit(field.getAttribute().getValue());

    //Check if digit count of Account Number is less than 4 or not
    if (numberOfDigit <= 4)
    {
        //Set The Notification
        field.setNotification("The account number should be more than 4 digits");
    }
    else
    {
        //Clear The Notification
        field.clearNotification();
    }
}

//Function To Get Count Of Digits
function CountDigit(number)
{
    return number.toString().length;
}

Output

Image The Screen shot displays the notification near Account Number field.

By Abhisek Sriramka
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
Leave a comment

Posted by on November 29, 2013 in WebResources

 

Tags: , , , , , , , , , , , , , , , , , ,

Changing Filter Condition in Associated View

Activities Associated View

Activities Associated View

Introduction

At times, we have the requirement to change the Filter Condition in an Associated View.

Background

In my case, the requirement was to show all the Activities when “Activities” Associated View is selected. The default Filter Condition in Activity Associated View is “Next 30 days“. I had to change it to “All“.

Code

Here is the code snippet to work this out. This function must be called on Load of the Form.

function filterAllActivities()
{
    //Calling function when activity is clicked
    document.getElementById("navActivities").onclick = function () {
        Mscrm.Details.loadArea(this, "areaActivities"); //loadArea is the predefined function

        //On load of the activity iframe change the filter
        document.getElementById("areaActivitiesFrame").onload = function () {
            var entityName = Xrm.Page.data.entity.getEntityName();
            var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);

            var doc = this.contentWindow.document; //Getting the document of the window

            //Getting the control of the 'Filter on' dropdown
            var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter");
            filterOn.value = "All"; //Changing the filter condition

            var evt = document.createEvent("HTMLEvents");
            evt.initEvent("change", false, true);
            filterOn.dispatchEvent(evt); //Dispatch event
        };
    };
}

By Ranjan Parhi
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
3 Comments

Posted by on November 19, 2013 in WebResources

 

Tags: , , , , , , , , , , , , , , ,

Skype Status on CRM Form

For the Impatient Guys…

…this is how it will look like…

Skype Online Status

Skype Online Status

Introduction

Let’s discuss the technique, by which we can easily integrate the Skype Status in our CRM Form.

We will show the Skype Status in Contact Form.

Mystery behind Skype Status

Skype Status in simply a combination of

  • Anchor to invoke the Skype Client
  • Image tag to render the Status Image

For Example

<a href="skype:mfsi_taditd?chat">
    <img src="http://mystatus.skype.com/balloon/mfsi_taditd" 
         style="border: none;" width="150" height="60" 
         alt="My status" />
</a>

Here…

  • <a href="skype:mfsi_taditd?chat"

    Indicates that, it will invoke the Skype Client.

    Refer Figure– Skype Prompt Box below.

    After you click on “Skype” App in that dialog, it will open Skype dialog for user “mfsi_taditd” (Figure– Skype Client Invoked).
    The parameter “chat” implies that, it will open the dialog for chatting. The other option is call, which will directly call the user. More Info at Skype buttons

    Skype Prompt Box

    Skype Prompt Box

    Skype Client Invoked

    Skype Client Invoked

  • <img src="http://mystatus.skype.com/balloon/mfsi_taditd"

    loads the Skype Status Image of user.

How will we implement this in CRM Form?

We will simply generate an Anchor and Image tag combination dynamically according to the entered Skype Name and populate that inside a Div. Thus, it will render the Skype Status of user.

Let’s discuss this stepwise.

Step By Step

Step – 1: Add one Field for Skype Name (Single Line of Text) in Contact Entity and include that in form

Skype Name Field on Form

Skype Name Field on Form

Step-2: Add HTML WebResource to Show the Skype Status

Skype Status HTML WebResource

Skype Status HTML WebResource

Now, add one WebResource in Contact Form just below the Skype Name Field and select SkypeStatus.html as the WebResource file in that WebResource Properties Window. See the following image.

Include Skype Status HTML WebResource in Form

Include Skype Status HTML WebResource in Form


The HTML file will show the Skype Status Image dynamically according to the Skype Name entered in the Skype Name Field (Described at Step-1). The code of HTML page is described below.

<html>
    <head>
	<script type="text/javascript" src="../Scripts/showSkypeStatus.js" 
		    language="javascript">
	</script>
    </head>
    <body onload="showSkypeStatus(false)">
	    <div id="divSkypeAnchor">
	    </div>
    </body>
</html>

We can see that, it is executing javaScript function showSkypeStatus onload of body, which is present in javaScript file showSkypeStatus.js.

This function is responsible for creating and populating the Div (divSkypeAnchor) with the required Anchor and Image tag combination. We are going to explore more about it in the next Step.

Step-3: Add javaScript WebResource to Dynamically populate the Status

Show Skype Status JavaScript WebResource

Show Skype Status JavaScript WebResource

The function inside the above javaScript file is described below.

/// <summary>
/// This method dynamically populates the Skype Status Div.
/// </summary>
/// <param name="boolean">isXrm: true- Xrm Present, false- Xrm present on parent.</param>
function showSkypeStatus(isXrm){
    var page;
    var divSkypeAnchor;

    // If Xrm is present.
    if(isXrm){
        page = Xrm.Page;
        
        var skypeWebResource = document.getElementById("WebResource_SkypeStatus");
        var innerDoc = skypeWebResource.contentDocument 
			|| skypeWebResource.contentWindow.document;
        
	    // Get the Skype Div.
	    divSkypeAnchor = innerDoc.getElementById("divSkypeAnchor");
    }
    // If Xrm is obtained from parent page.
    else{
        page = parent.Xrm.Page;

	    // Get the Skype Div.
        divSkypeAnchor = document.getElementById("divSkypeAnchor");
    }
	
    if(page != null){
	    // Get the Skype Name (new_skypename) of the Contact from page.
        if(page.getAttribute("new_skypename").getValue() != null 
	    && page.getAttribute("new_skypename").getValue() != ""){
	        var skypeName = page.getAttribute("new_skypename").getValue();
			
		    // Create the Anchor and Image combination using the "skypeName"
	        var skypeAnchor = "<a href='skype:" + skypeName + "?chat'>";
		    skypeAnchor += "      <img src='http://mystatus.skype.com/balloon/" + skypeName + "' ";
		    skypeAnchor += "          style='border: none;' width='150' height='60' ";
		    skypeAnchor += "          alt='Status of " + skypeName + "' title='Status of " + skypeName + "' />";
		    skypeAnchor += "   </a>";

	        // Assign the "skypeAnchor" to the Skype Div.
            divSkypeAnchor.innerHTML = skypeAnchor;
	    }
    }
}

Description of Code

In the function, the main aim is to assign the Anchor and Image tag combination along with the Skype Name to the Div (divSkypeAnchor).

Let’s divide the function to two parts.

Part-1: Getting the Skype Div (divSkypeAnchor) and Page

The Contact Form is the Parent Form and the Div present inside the WebResource, is rendered as Child iFrame.
As the Skype Div (divSkypeAnchor) is present inside the iFrame, if we will access it using document object, then the document should refer to the iFrame (WebResource) and not the Parent Contact Form.
If we use

document.getElementById("divSkypeAnchor")

, then document should be the WebResource (iFrame).

As this function will be called both on Form Load and Skype Field onChange Events, we need to make sure that document refers to the Child iFrame in both cases. The argument isXrm is used to recognize whether the request comes from the HTML WebResource (Form Load Event) or the Parent Page (Skype Field onChange Events).

Let’s discuss the way, by which, we will assign value to Skype Div (divSkypeAnchor) during these events.

  • Form Load

    On Form Load, it will load the HTML WebResource and on the WebResource load, we have called the method like below. More about the WebResource at Step-2.

        <body onload="showSkypeStatus(false)">
    

    As the function is called inside the HTML WebResource, so we can directly get the Div (divSkypeAnchor) from document (as it refers to the iFrame document).

        // If Xrm is obtained from parent page.
        else{
            page = parent.Xrm.Page;
    
    	    // Get the Skype Div.
            divSkypeAnchor = document.getElementById("divSkypeAnchor");
        }
    
  • Skype Field onChange

    The main issue here is, we can’t get the Skype Div (divSkypeAnchor) directly from the document (as it will refer to the Parent Contact page). This is because the event executes on Skype Name Field onChange of Parent Contact Page.
    To indicate that the request is going from Contact Form, we are passing isXrm as true. More at Step-4.
    So, “if” part executes and we are getting the WebResource by…

    document.getElementById("WebResource_SkypeStatus")

    Then innerDoc is obtained by

    var innerDoc = skypeWebResource.contentDocument 
                    || skypeWebResource.contentWindow.document;

    , which refers to the iFrame Document.

    Now problem is solved. Using the innerDoc, we can now get the Div (divSkypeAnchor).

        // If Xrm is present.
        if(isXrm){
            page = Xrm.Page;
    
            var skypeWebResource = document.getElementById("WebResource_SkypeStatus");
            var innerDoc = skypeWebResource.contentDocument 
                            || skypeWebResource.contentWindow.document;
    
    	    // Get the Skype Div.
    	    divSkypeAnchor = innerDoc.getElementById("divSkypeAnchor");
        }
    

Part-2: Assigning value to the Skype Div (divSkypeAnchor)

    if(page != null){
	    // Get the Skype Name (new_skypename) of the Contact from page.
        if(page.getAttribute("new_skypename").getValue() != null
	    && page.getAttribute("new_skypename").getValue() != ""){
	        var skypeName = page.getAttribute("new_skypename").getValue();

		    // Create the Anchor and Image combination using the "skypeName"
	        var skypeAnchor = "<a href='skype:" + skypeName + "?chat'>";
		    skypeAnchor += "      <img src='http://mystatus.skype.com/balloon/" + skypeName + "' ";
		    skypeAnchor += "           style='border: none;' width='150' height='60' ";
		    skypeAnchor += "           alt='Status of " + skypeName + "' title='Status of " + skypeName + "' />";
		    skypeAnchor += "   </a>";

		    // Assign the "skypeAnchor" to the Skype Div.
            divSkypeAnchor.innerHTML = skypeAnchor;
	    }
    }

First we are getting the value of Skype Name field using the page variable

var skypeName = page.getAttribute("new_skypename").getValue();

This page variable is determined by isXrm parameter as we discussed in Part-1.
Using the skypeName, the skypeAnchor (Described at Mystery behind Skype Status) is created and assigned to divSkypeAnchor in the next line.

Step-4: Register onChange Event for Skype Name Field

Go to Contact Form Properties. Add showSkypeStatus.js in Form Libraries Section and Skype Name onChange Handler in Event Handlers Section.

Contact Form Properties

Contact Form Properties

The Event Handler Properties is shown below. Note that function here is showSkypeStatus and parameter passed is true for isXrm. (Described at here).

Skype Name onChange Handler Properties

Skype Name onChange Handler Properties

Gallery

Are you Away or Busy? Check how it shows the Status on the Contact Form.

Skype Away Status

Skype Away Status

Skype Busy Status

Skype Busy Status

Downloads

HTML WebResourceSkypeStatus.html
javaScript WebResourceshowSkypeStatus.js

What you feel?

If you find this Blog as helpful, then please Like and Share among your Friends and Colleagues and add some Comments. It really means a lot. That will also help to fine-tune my technical skills.

Hope you enjoyed reading the Blog.

By Tadit Kumar Dash
Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
3 Comments

Posted by on September 10, 2013 in WebResources

 

Tags: , , , , , , , , , , , , , , , , , , ,

Using CRM LookUp functionality in a Silverlight WebResource with CRM Look and Feel

Introduction

In this blog, I will show you how to use the LookUp functionality of CRM in a Silverlight WebResource.

I am trying to create a LookUp for the Account inside a Contact record.

Design

Let’s first go for the Design.

In the Design, let’s add a RichTextBox and a LookUp image similar to the CRM LookUp image.

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="SilverlightApplicationLookUpDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <sdk:Label Height="20" Width="50" x:Name="lblLookup" HorizontalAlignment="Left" Content="Account" Margin="62,56,0,0" VerticalAlignment="Top"/>
        <RichTextBox Background="White" FontSize="10" VerticalScrollBarVisibility="Disabled" IsReadOnly="True" Height="21" HorizontalAlignment="Left" Margin="112,54,0,0" Name="txtLookUp" VerticalAlignment="Top" Width="200" TabIndex="1" />
        <Image Height="21" Width="21" HorizontalAlignment="Left" Margin="313,53,0,0" Name="ImgLookUp" MouseLeftButtonDown="LocalImage_MouseLeftButtonDown" Source="/SilverlightApplicationLookUpDemo;component/Images/btn_off_lookup.png" VerticalAlignment="Top"/>
    </Grid>
</UserControl>

It will look like below.

Capture

Code Behind

In the Code Behind, let’s insert the Event that will be fired, when the Image gets clicked.

The whole code will look something like this.

using System.Json;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;

namespace SilverlightApplicationLookUpDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void LocalImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string lookupId = string.Empty;
            string lookupName = string.Empty;
            string contactId = "7C1EF3C4-39D3-E211-8A25-B4B52F566DF2";
            string baseUrl = "https://example.crm.dynamics.com";
            string objectTypesContact = "2";

            //Relative URL for the LookUp
            string lookUpRecordUrl = "/_controls/lookup/lookupinfo.aspx?AllowFilterOff=1&DefaultType=1&" +
"DisableQuickFind=0&DisableViewPicker=0&LookupStyle=single&ShowNewButton=1&ShowPropButton=1&" +
"browse=false&currentid=" + contactId + "&objecttypes=" + objectTypesContact;

           //Complete URL to open the LookUp
           string lookUpUrl = baseUrl + lookUpRecordUrl;

           //Open the Modal Window for the LookUp
           dynamic returnedParams = HtmlPage.Window.Invoke("showModalDialog", lookUpUrl, null, "dialogWidth:500px;dialogHeight:700px");

           //For earlier Rollups, it will return a json object
           if (returnedParams.items)
           {
               lookupId = returnedParams.items[0].id;
               lookupName = returnedParams.items[0].name;
           }

           //For Rollup 12, as in Rollup 12 returnedparams would
           //be a json string instead of a json object.
           else
           {
               JsonValue jsonValue = JsonValue.Parse(returnedParams);
               JsonObject jsonObject = jsonValue as JsonObject;

               //user selected
               lookupId = jsonObject["items"][0]["id"].ToString();
               lookupName = jsonObject["items"][0]["name"].ToString();
           }

           //Add style to the TextBox
           txtLookUp.Foreground = new SolidColorBrush(Colors.Blue);

           //Add selected item to the fiscal period TextBox
           Paragraph paragraph = new Paragraph();
           Underline underline = new Underline();
           Run run = new Run() { Text = lookupName };

           underline.Inlines.Add(run);
           paragraph.Inlines.Add(underline);
           txtLookUp.Blocks.Clear();
           txtLookUp.Blocks.Add(paragraph);
       }
    }
}

Now let’s add the WebResource to a Contact entity.

Output

So, after implementing, we will see something like this.

Image

Image

Notes

  1. For the demo, I have hard-coded the Contact Id and objecttype for Contact, but we can also pass them as QueryString Parameter/Custom Parameter for the Web Resource.
  2. For Server URL, we can use the “SilverlightUtility.GetServerBaseUrl()" function.
  3. The “SilverlightUtility.cs" can be found at location sdk\samplecode\cs\silverlight\soapforsilverlight\soapforsilverlightsample in the SDK provided by Microsoft.

By Dibyasingh Tripathy
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
2 Comments

Posted by on August 7, 2013 in WebResources

 

Tags: , , , , , , , , , , , , , , ,

 
%d bloggers like this: