WebMasterSam

.Net, SEO, Dynamics CRM, AdSense/AdWords, Dating sites, Silverlight, Web hosting and more

About me

I'm an IT consultant working primarily with the .Net Framework as a developper and architect. I also work on my own on my personnal dating websites. I've been developping websites since 2000.

If you like what I do, feel free to support me

PayPal - The safer, easier way to pay online!

Bookmark

Bookmark and Share

Last comments

None

Display a MessageBox in Silverlight

 

For people who tries to find the "MessageBox" class in Silverlight to display a message in a pop-up like we do in WinForms will have difficulty to find it because this doesn't work the same way. Because Silverlight runs in the browser, the message box is the one that is available in JavaScript: the "alert" method.


System.Windows.Browser.HtmlPage.Window.Alert("Your message goes here");

In the Window object (System.Windows.Browser.HtmlPage.Window) you will find some other things like "Prompt", "Navigate", "AttachEvent" and "Confirm". It shows how integrated with the browser and the JavaScript code Silverlight is, and this is a real good thing because you can easily make those 2 technologies talk together.

 

Posted: Apr 20 2009, 16:33 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | JavaScript | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

JavaScript AJAX wrapper for CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

This class is a clean wrapper for all your AJAX calls.

JavaScript AJAX wrapper for CRM 4.0


function AjaxWrapper()
{
    var object = this;

    object.Request = NewRequest();
    object.Request.onreadystatechange = CompleteRequest;

    this.Sync = true;
    this.Method = "GET";
    this.URL = "";
    this.WebServiceMethod = "";
    this.Parameters = new ParameterCollection();

    this.Execute = ExecuteRequest;
    this.AsyncCallbackMethod = null;

    this.ResultXML = null;
    this.ResultText = null;

    function NewRequest()
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else
            return new ActiveXObject("Microsoft.XMLHTTP");
    }

    function ExecuteRequest()
    {
        var parameters = object.Parameters.toString();        

        ResetRequest();        

        if (this.Method.toUpperCase() == "POST")
        {
            if (object.WebServiceMethod.length > 0)
                object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod, !object.Sync);
            else
                object.Request.open(object.Method, object.URL, !object.Sync);            

            object.Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            object.Request.send(object.Parameters);
        }
        else if (this.Method.toUpperCase() == "GET")
        {
            if (object.WebServiceMethod.length > 0 && parameters.length > 0)
                object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod + "?" + parameters, !object.Sync);
            else if (object.WebServiceMethod.length > 0)
                object.Request.open(object.Method, object.URL + "/" + object.WebServiceMethod, !object.Sync);
            else if (parametres.length > 0)
                object.Request.open(object.Method, object.URL + "?" + parameters, !object.Sync);
            else
                object.Request.open(object.Method, object.URL, !object.Sync);            

            object.Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            object.Request.send();
        }
        else
        {
            throw "The method '" + this.Method.toUpperCase() + "' is not supported !";
        }        

        if (object.Sync)
            FinishRequest(object.Request.responseText);
    }

    function CompleteRequest()
    {
        if (object.Request.readyState == 4)
        {
            if (object.Request.status == 200)
            {
                FinishRequest(object.Request.responseText);                

                if (object.AsyncCallbackMethod != null)
                    object.AsyncCallbackMethod();
            }
        }
    }

    function ResetRequest()
    {
        object.Request = NewRequest();
        object.Request.onreadystatechange = CompleteRequest;
    }    

    function FinishRequest(retourTexte)
    {
        var xmlDoc = new ActiveXObject("MSXML2.DOMDocument");

        object.ResultText = object.Request.responseText;        

        try
        {
            xmlDoc.loadXML(object.Request.responseText);            

            if (xmlDoc.parsed && xmlDoc.xml.length > 0)
                object.ResultXML = xmlDoc;
            else
                object.ResultXML = null;
        }
        catch (ex)
        {
            object.ResultXML = null;
        }
    }
}

The ParameterCollection to help adding QueryString parameters safely (well-encoded values)


function ParameterCollection()
{
    this._list = new Array();
    
    this.Add = function (name, value)
    {
        this._list[this._list.length] = new Array(name, value);
    }    

    this.toString = function ()
    {
        var queryString = "";        

        for (var i=0; i<this._list.length; i++)
        {
            if (queryString.length > 0)
                queryString = queryString + "&";            

            queryString = queryString + this._list[i][0] + "=" + encodeURIComponent(this._list[i][1]);
        }        

        return queryString;
    }
}

Posted: Apr 13 2009, 17:17 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript | Programming
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Hide and show items in a picklist in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

Those methods seems a lot more complicated than they has to be because we can't really hide and show items in picklists (HTML select). In HTML if you want to hide an "option" of a select, you need to remove it ! So when you want to show it back again you need to readd it to the list, and in addition to that, it will be placed at the end, not where he was before... so I created methods to help people to really hide and show CRM picklist items only by their value.

Hide a picklist item in CRM 4.0


function HidePickListItem(listID, value)
{
    var objList = document.getElementById(listID);

    // If the list has never been saved, save it now
    if (objList.SavedList == null)
    {
        var arrListe = new Array();        

        for (var i=0; i<objList.options.length; i++)
        {
             arrListe[i] = new Object();
             arrListe[i].value = objList.options[i].value;
             arrListe[i].Libelle = objList.options[i].text;
             arrListe[i].Visible = true;
        }

        objList.SavedList = arrListe;
    }

    for (var i=0; i<objList.SavedList.length; i++)
        if (objList.SavedList[i].value == value)
            objList.SavedList[i].Visible = false;

    for (var i=objList.options.length - 1; i>=0; i--)
        if (objList.options[i].value == value)
            objList.options.remove(i);
}

Show a picklist item that has been hidden in CRM 4.0


function ShowPickListItem(listID, value)
{
    var objList = document.getElementById(listID);

    if (objList.SavedList != null)
    {
        var selValue = null;
        var indexInsertion = 0;

        for (var i=0; i<objList.SavedList.length; i++)
            if (objList.SavedList[i].value == value)
                objList.SavedList[i].Visible = true;

        // Keep the selected value so we can reselect it after
        if (objList.selectedIndex > -1)
            selValue = objList.options[objList.selectedIndex].value;

        // Remove all the items in the list
        for (var i=objList.options.length - 1; i>=0; i--)
           objList.options.remove(i);

        // Add the items that must be visible
        for (var i=0; i<objList.SavedList.length; i++)
        {
             if (objList.SavedList[i].Visible)
             {
                var oOption = document.createElement('option');         

                oOption.text = objList.SavedList[i].Libelle;
                oOption.value = objList.SavedList[i].value;                

                objList.options.add(oOption);
            }
        }        

        // Reselect the item that was selected
        for (var i=0; i<objList.options.length; i++)
            if (objList.options[i].value == selValue)
                objList.selectedIndex = i;
    }
}

Posted: Apr 13 2009, 16:40 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Maximize the CRM child windows

 

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM. One of the client need was that all the windows appear fullscreen because their users are not familiar with mutliple levels of pop-up so by maximizing every window, you always have the feeling to be in the same window.

Maximize the window in CRM 4.0


function MaximizeWindow()
{
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height);
}

 

Posted: Apr 13 2009, 16:27 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to get selected items in a CRM grid in CRM 4.0

 

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

Get the selected items in a CRM grid in CRM 4.0

With this function you get only the GUIDs of the records selected.


function GetSelectedItemsInGrid()
{
    return getSelected("crmGrid");
}

 

Posted: Apr 13 2009, 16:22 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to hide and show left navigation items in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

The first you need to do when you want to manipulate the left navigation section is to create a general function to get a reference to a navigation block. The reason is because each time you want to hide or show a block or nav item you need the DOM reference of the navigation block so instead of copying the code every time, you write a function and you call it everywhere.

Get the DOM reference to a left navigation block in CRM 4.0


function GetNavBlock(block)
{
    var objBlockDetails = document.getElementById("_NA_Info");
    var objBlockSales = document.getElementById("_NA_SFA");
    var objBlockService = document.getElementById("_NA_CS");
    var objBlockMarketing = document.getElementById("_NA_MA");
    var objNavBlock = null;    

    if (objBlockDetails.innerText.substr(0, objBlockDetails.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
        objNavBlock = objBlockDetails;
    else if (objBlockSales.innerText.substr(0, objBlockSales.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
        objNavBlock = objBlockSales;
    else if (objBlockService.innerText.substr(0, objBlockService.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
        objNavBlock = objBlockService;
    else if (objBlockMarketing.innerText.substr(0, objBlockMarketing.innerText.indexOf(":")).toLowerCase() == block.toLowerCase())
        objNavBlock = objBlockMarketing;
    else
        throw "The navigation block '" + block + "' doesn't exists.";

    return objNavBlock;
}

Hide a navigation block in CRM 4.0


function HideNavBlock(block)
{
    var objNavBlock = GetNavBlock(block);

    objNavBlock.parentElement.style.display = "none";
}

Show a navigation block in CRM 4.0


function ShowNavBlock(block)
{
    var objNavBlock = GetNavBlock(block);

    objNavBlock.parentElement.style.display = "";
}

Hide a navigation item in a navigation block in CRM 4.0


function HideNavItem(block, item)
{
    var objNavBlock = GetNavBlock(block);

    for (var i=0; i<objNavBlock.nextSibling.childNodes.length; i++)
    {
        var menuItem = objNavBlock.nextSibling.childNodes[i];

        if (menuItem.childNodes[0].childNodes[1].innerText == item)
            menuItem.style.display = "none";
    }
}

Show a navigation item in a navigation block in CRM 4.0


function ShowNavItem(block, item)
{
    var objNavBlock = GetNavBlock(block);

    for (var i=0; i<objNavBlock.nextSibling.childNodes.length; i++)
    {
        var menuItem = objNavBlock.nextSibling.childNodes[i];

        if (menuItem.childNodes[0].childNodes[1].innerText == item)
            menuItem.style.display = "";
    }
}

Posted: Apr 13 2009, 16:04 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to hide, show and select tabs in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

Hide a tab in CRM 4.0


function HideTab(tabNumber)
{
    var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");    

    tab.style.display = "none";
}

Show a tab in CRM 4.0


function ShowTab(tabNumber)
{
    var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");    

    tab.style.display = "";
}

Select a tab in CRM 4.0


function SelectTab(tabNumber)
{
    var tab = document.getElementById("tab" + (tabNumber - 1).toString() + "Tab");

    tab.click();
}

Posted: Apr 13 2009, 16:00 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to hide and show sections in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

Hide a section in a tab in CRM 4.0


function HideSection(tabNumber, sectionNumber)
{
    var tab = document.getElementById("tab" + (tabNumber - 1).toString());    

    tab.childNodes[0].rows[(sectionNumber - 1).toString()].style.display = "none";
}

Show a section in a tab in CRM 4.0


function ShowSection(tabNumber, sectionNumber)
{
    var tab = document.getElementById("tab" + (tabNumber - 1).toString());    

    tab.childNodes[0].rows[(sectionNumber - 1).toString()].style.display = "";
}

Posted: Apr 13 2009, 15:30 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to disable and enable fields in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

Disable a field in CRM 4.0


function DisableField(id)
{
    var lookup = id.indexOf('_ledit') > 0;
    var objField = lookup ? crmForm.all[id.replace('_ledit', '')] : crmForm.all[id];

    if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "radio")
        objField.disabled = true;
    else if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "checkbox")
        objField.disabled = true;
    else if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "text")
        objField.readOnly = true;
    else if (objField.tagName.toUpperCase() == "SELECT")
        objField.disabled = true;
    else if (objField.tagName.toUpperCase() == "TEXTAREA")
        objField.readOnly = true;
    else
        objField.Disabled = true;

    if ((objField.tagName.toUpperCase() == "INPUT" && objField.type != "radio" && objField.type != "checkbox") || objField.tagName.toUpperCase() == "SELECT" || objField.tagName.toUpperCase() == "TEXTAREA")
        objField.style.backgroundColor = "#DDDDDD";
}

Enable a field in CRM 4.0


function EnableField(id)
{
    var lookup = id.indexOf('_ledit') > 0;
    var objField = lookup ? crmForm.all[id.replace('_ledit', '')] : crmForm.all[id];    

    if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "radio")
        objField.disabled = false;
    else if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "checkbox")
        objField.disabled = false;
    else if (objField.tagName.toUpperCase() == "INPUT" && objField.type != "text")
        objField.readOnly = false;
    else if (objField.tagName.toUpperCase() == "SELECT")
        objField.disabled = false;
    else if (objField.tagName.toUpperCase() == "TEXTAREA")
        objField.readOnly = false;
    else
        objField.Disabled = false;        

    if ((objField.tagName.toUpperCase() == "INPUT" && objField.type != "radio" && objField.type != "checkbox") || objField.tagName.toUpperCase() == "SELECT" || objField.tagName.toUpperCase() == "TEXTAREA")
        objField.style.backgroundColor = "";
}

Posted: Apr 13 2009, 15:22 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

How to hide and display fields in CRM 4.0

If you already worked with Microsoft Dyamics CRM 4.0, you know that almost everything you do with JavaScript is considered a "hack" because you manipulate the DOM of the pages by yourself. Because of this I decided to give you some help with differents helper methods I developped at my day job.

I'm currently working on a big development project involving CRM.

How to hide a field in CRM 4.0

Here's a secure method that will correctly hide a field (lookups are a bit tricky).


function HideField(id)
{
    var objField = crmForm.all[id];
    var lookup = id.indexOf('_ledit') > 0 || objField.tagName.toUpperCase() == "IMG";
    var objFieldLookup = objField.tagName.toUpperCase() == "IMG" ? crmForm.all[id + '_d'] : crmForm.all[id.replace('_ledit', '_d')];

    objField.style.visibility = 'hidden';

    if (lookup)
        objFieldLookup.style.visibility = 'hidden';
}

How to show a field in CRM 4.0

Here's a secure method that will correctly show a field


function ShowField(id)
{
    var objField = crmForm.all[id];
    var lookup = id.indexOf('_ledit') > 0 || objField.tagName.toUpperCase() == "IMG";
    var objFieldLookup = objField.tagName.toUpperCase() == "IMG" ? crmForm.all[id + '_d'] : crmForm.all[id.replace('_ledit', '_d')];

    objField.style.visibility = 'visible';

    if (lookup)
        objFieldLookup.style.visibility = 'visible';
}

Posted: Apr 13 2009, 15:09 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: CRM 4.0 | JavaScript
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
LINK BUILDING IS PROHIBITED ON THIS WEBSITE