Archive

Archive for the ‘JavaScript’ Category

Mini Preview Window for Contact Lookup Field

March 9th, 2010

Preview Field

Looks cool doesn’t it. well here goes nothing..

to achieve the above you will need the following (click read more link..)


// the following code is for the hover over lookup window

function OnCrmPageLoad()
{
/*
Reference the to Lookup, Provide the lookup (control) id.
*/
var PrvToLui = new LookupPreview("new_primarycontactid");
/*
Add Account Preview Information ,
returns an account entity wrapper object
*/
var accountEntity = PrvToLui.AddEntity("account");

/*
Add Account Preview Attributes,
Provide lable and schema name for each attribute
*/
accountEntity.AddAttribute("Business Phone","address1_line1");
accountEntity.AddAttribute("Mobile Phone","address1_city");
accountEntity.AddAttribute("Fax","address1_stateorprovince");
accountEntity.AddAttribute("E-mail","address1_postalcode");
/*
Add Related Entity (Primary Contact) Information
AddLinked requires the entity name and
lookup field schema name on the account.
*/
var contactEntity = accountEntity.AddLinked("contact","primarycontactid");
contactEntity.AddAttribute("Primary Contact","fullname");
contactEntity.AddAttribute("Contact Phone","telephone1");

/* ------------------------------------------------------------------ */

//Contact Entity Preview
var contactEntity = PrvToLui.AddEntity("contact");
contactEntity.AddAttribute("Business Phone","telephone1");
contactEntity.AddAttribute("Mobile Phone","mobilephone");
contactEntity.AddAttribute("Fax","fax");
contactEntity.AddAttribute("E-mail","emailaddress1");

var accountEntity = contactEntity.AddLinked("account","parentcustomerid");
accountEntity.AddAttribute("Parent Company", "name");
accountEntity.AddAttribute("Parent Street","address1_line1");
accountEntity.AddAttribute("Parent Suburb","address1_line2");
accountEntity.AddAttribute("Parent State","address1_stateorprovince");
accountEntity.AddAttribute("Parent Postcode","address1_postalcode");
accountEntity.AddAttribute("Parent Website","websiteurl");
/* ------------------------------------------------------------------ */

}
Read more...

MSCRM-Admin CRM 4.0, JavaScript , , , , ,

CRM 4: Adding tooltips to fields on forms

July 14th, 2009

Tooltips are little help messages explaning a field or label (if you hover over a label you will notice a tooltip), I had a requirenment for adding a tooltip to a custom field with some custom help text.

After some digging through i found out the correct JScript property and method:

crmForm.all.my_custom_attribute_c.title = “Add a value here and it should get automatically populated..”;

End Result:

 

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , ,

Microsoft Visual Studio 2008 trial finished and still need to use it??

June 25th, 2009

Simple answer, just change the date/clock back 20 days in control panel.

It should now say:  You have 20 days left in the trial period.

MSCRM-Admin JavaScript , ,

CRM4: Hiding tabs and sections

June 17th, 2009

Hello all,

I am currently working on a small CRM project and one of the requirements was to hide a section and a tab onLoad.

// Hiding the Contract section

crmForm.all.contractid_c.parentElement.parentElement.style.display=’none’;

// Hide the KB article tab (2nd Tab)

crmForm.all.tab1Tab.style.display=’none’;

I’m sure you can use this in other ways (i.e:. onChange, onClick etc..).

Happy Coding!

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , ,

Call/Request a workflow in CRM 4.0 using Javascript

May 25th, 2009
  1. Add a button on Form’s Toolbar/Grid’s Menu Bar for the entity in ISV config file (export ISV config)
  2. Call launchOnDemandWorkflowForm (for button on Form) or launchOnDemandWorkflow (for button on grid) functions and pass the parameters sGrid, iObjType and workflowId.
  3. Save the config file and import it to CRM.

An example of this could be:

<Entity name="account">
<ToolBar ValidForCreate="0" ValidForUpdate="1">
<Button Icon="/_imgs/mybutton.jpg" JavaScript="launchOnDemandWorkflowForm('', '10029','{00000000-0000-0000-0000-000000-00000}');" PassParams="1" WinParams="" WinMode="0">
<Titles>
<Title LCID="1033" Text="Send Email" />
</Titles>
<ToolTips>
<ToolTip LCID="1033" Text="Send Welcome Email" />
</ToolTips>
</Button>
</Entity>

Or you can alternatively request it from the web service:

/* the function */
ExecuteWorkflow = function(entityId, workflowId)
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"ExecuteWorkflowRequest\">" +
" <EntityId>" + entityId + "</EntityId>" +
" <WorkflowId>" + workflowId + "</WorkflowId>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return(resultXml.xml);
}

// call the workflow
var theWorkflowId = "3FD2DD58-4708-43D7-A21B-F0F90A0AA9F2"; //change to your workflow Id
ExecuteWorkflow(crmForm.ObjectId, theWorkflowId);

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , ,

Add a Button to a Form

May 23rd, 2009

This post is to show how to add a Button to a MS CRM Form, not to the Navigation Pane nor to the Menu Bar, but to the actual Form itself.
In this post I will show a simple usage of the Button, to show its function. You can understand that more advanced functions can be triggered by the button, but that’s not the aim of this post.For this example I have used the default Contact Form. The Address Section is hidden onLoad and a Button is shown.

Button on Form

By Clicking on the Button the Section with the Address Details is shown again. In this example the Button Disappears, because it has no use anymore. (I could have added a function to hide the section again).

Button on Form2

To achieve the above I have created a new Section with a new Attribute (new_button).

Button on Form3

Next to that I placed the following Script in the onLoad of the Form:

Update: 9th March 2010 - updated code blocks - wordpress broke the code!

// Start of onLoad Code

//to hide the address details onload
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display = 'none';

// Replace the attribute new_button with the button and create a link to the onclick function
function CreateButton() {
var fieldTable = crmForm.all.new_button_d;
var html = "<table border='0' cellspacing='0' cellpadding='0'><tr><td width='0px'>" + fieldTable.innerHTML + "</td><td width='200px'><input type='button' value='Show Address Details' onclick='Button_OnClick()' style='background-color:#d8e8ff' style ='border-width:2px'/></td></tr></table>";
fieldTable.innerHTML = html;
//hide the new_button attribute
document.all.new_button.style.display='none';
crmForm.all.new_button_c.innerText="";
}
// Function to be triggered onClick
Button_OnClick = function() {
//to show the address details
crmForm.all.address1_name_c.parentElement.parentElement.parentElement.style.display ='block';
//In this case I hide the button, because I haven't added the button has not function anymore in this case
crmForm.all.new_button_c.parentElement.parentElement.parentElement.style.display ='none';
}
// Initialization: Execute the selected sample
CreateButton();

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , ,

CRM 4.0: Notes Count on any Entity

May 20th, 2009

NotesCount is a client side JScript customization, which enables CRM useres to recognize the amount of attached notes or attachments to any CRM record (e.g. contact, account, case, …) within the tab on top of the main form of the record.
Intention
NotesCount is intended to improve the UX of all Microsoft Dynamics CRM 4.0 users. By showing the amount of attached notes or files referenced to CRM records without opening the notes tab it will reduce the risk to miss important information.

screenshot 

More info & Download: http://notescount.codeplex.com/

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , ,

Show no. of open or closed activities (history) on the CRM form.

May 18th, 2009

Hello all,

Have you ever wanted to see the total no. of outstanding/completed activities on a Case, Account, Opportunity, Contact etc..?  

Well now you can, simply add the following JavaScript code to the onLoad event of the entity, it will query the webservice and it will give you the exact count of open/closed activities.

Update: 9th March 2010 - I have updated the code below and tested.

// this code is to get the number of activities and historical activities.
var buXml = GetRegardingActivity();
if(buXml != null)
{
    var buNodes = buXml.selectNodes("//BusinessEntity/q1:statecode"); // CRM 4.0
    var iActivity = 0;
    var iHistory = 0;

    if(buNodes != null )
    {
        /*get values*/
        for( i = 0; i < buNodes.length; i++)
        {
            switch(buNodes[i].text)
            {
                case "Open" : iActivity++; break;
                case "Scheduled" : iActivity++; break;
                case "Completed" : iHistory++; break;
                case "Canceled" : iHistory++; break;
            }
        }

        if(document.getElementById('navActivities') != null)
        {
            document.getElementById('navActivities').getElementsByTagName('NOBR')[0].innerText = document.getElementById('navActivities').getElementsByTagName('NOBR')[0].innerText + " (" + iActivity + ")";
        }

        if(document.getElementById('navActivityHistory') != null)
        {
            document.getElementById('navActivityHistory').getElementsByTagName('NOBR')[0].innerText = document.getElementById('navActivityHistory').getElementsByTagName('NOBR')[0].innerText + " (" + iHistory + ")";
        }
    }
}

function GetRegardingActivity()
{
    var xml = "" +
    "<?xml version="1.0" encoding="utf-8"?>" +
    "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">" +
    GenerateAuthenticationHeader()  +
    " <soap:Body>" +
    "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
    "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
    " xsi:type='q1:QueryExpression'>"+
    " <q1:EntityName>activitypointer</q1:EntityName>" +
    " <q1:ColumnSet xsi:type="q1:ColumnSet">" +
    " <q1:Attributes>" +
    " <q1:Attribute>statecode</q1:Attribute>" +
    " </q1:Attributes>" +
    " </q1:ColumnSet>" +
    " <q1:Distinct>false</q1:Distinct>" +
    " <q1:Criteria>" +
    " <q1:FilterOperator>And</q1:FilterOperator>" +
    " <q1:Conditions>" +
    " <q1:Condition>" +
    " <q1:AttributeName>regardingobjectid</q1:AttributeName>" +
    " <q1:Operator>Equal</q1:Operator>" +
    " <q1:Values>" +
    " <q1:Value xsi:type="xsd:string">" + crmForm.ObjectId + "</q1:Value>" +
    " </q1:Values>" +
    " </q1:Condition>" +
    " </q1:Conditions>" +
    " </q1:Criteria>" +
    " </query>" +
    "</RetrieveMultiple>"+
    " </soap:Body>" +
    "</soap:Envelope>" +
    "";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    return resultXml;
}

Any comments or suggestions are welcome!

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , ,

Add custom toolbar buttons to the Case Entity form.

May 17th, 2009

Hi All,

Have you ever wanted to add some toolbar buttons to the CASE/CONTACT/ACCOUNT form?

Well now you can, you can use the ISV.config provided by CRM.

  1. Export the ISV Config Customizations from CRM
  2. Edit the XML file
  3. Find the <entity name=”incident”> node and add the following - I couldn’t paste the XML because of wordpress limitations.

  4. Note: the following are custom images: taskicon.gif, emailicon.gif and phonecallicon.gif.

  5.  Save the XML and import into CRM and publish the customizations.

Code explantion:

JavaScript="locAddActTo(4210)" PassParams="0" WinParams="" WinMode="0" Client="Web, Outlook" AvailableOffline="true"

Here we are using the CRM javascript function locAddActTo() and using the entity identifier (this being a phone call) which is located in the SDK and we are telling CRM to show this button is Outlook and the web version of CRM

JavaScript="resolve();" PassParams="0" WinParams="" WinMode="0" Client="Web, Outlook" AvailableOffline="true"

We are using the resolve() function on the case entity form which will resolve the case like you would when going to the actions menu > resolve case

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , ,

Hiding Sidebar Navigation (Related Entities)

September 18th, 2008

Hi Guys,

Recently for a client, we had to create some many-to-1 relationship from Contact to Accounts & Opportunities.  We then had the problem of the related entity navigation on the side showing up.  They didn’t want to see all these related navigations. I added some onLoad code on the contact form to hide the Sidebar navigation.

Before:

The key is to get the relationship Elementid from the source code of the page (Press Ctrl + N to open new window, then click on the ‘view’ menu and click ’source’). Then find the Name of the Navigation and find the element id:

onLoad code:
document.getElementById("nav_new_contact_account_dm1").style.display = "none";
document.getElementById("nav_new_contact_account_dm2").style.display = "none";
document.getElementById("nav_new_contact_account_dm3").style.display = "none";
document.getElementById("nav_new_contact_account_dm4").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm1").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm2").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm3").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm4").style.display = "none";

After:

I hope this helps you all and gives you some idea of how powerful JavaScript & CRM are.

-MSCRM Person

MSCRM-Admin CRM 4.0, Customizations, JavaScript , , , , , ,