Embed
Email

MS CRM

Document Sample
MS CRM
Shared by: Trinadh Kumar B
Stats
views:
6
posted:
2/11/2012
language:
pages:
17
Microsoft Dynamics CRM : How to customize a form using Javascript

Author: Pradip Shukla



One can customize a Microsoft CRM form using javascript with lots of ease.



 Navigate to Go To ->Settings ->Customization

 Select Customization Entities

 Double Click on the entity that is needed for customization.

 Click on Forms and Views and then double click on Form

 Select Form Properties from Common Task panel.

 It will open up the Form Properties dialog box with OnLoad and OnSave events.

 Select any event and click on edit.



It will open up the event detail properties dialog box where one can enter the java script for

customization. The code will be called when the event is triggered.



Following are few examples of customizing the Account form at Page Load

Change the Fore color of Label:

// it will change the Account Number Label to green bold

crmForm.all.accountnumber_c.innerHTML = "" +

crmForm.all.accountnumber_c.innerText + "";



Change the background color of the form

document.all.tab0.style.backgroundColor = 'white';//General tab

document.all.tab1.style.backgroundColor = 'white';//Details tab

document.all.tab2.style.backgroundColor = 'white';//Administration tab

document.all.tab3.style.backgroundColor = 'white'; //Notes tab



Disable a form

document.body.disabled = true;



Hide an entire row

var accountname = crmForm.all.name;

while ((accountname.parentNode != null) && (accountname.tagName.toLowerCase()

!= "tr"))

{

accountname = accountname.parentNode;

}

if (accountname.tagName.toLowerCase () == "tr")

{

accountname.style.display = "none";

}



Retrieving the text of a lookup control

var list = crmForm.all..DataValue;

if (list [0] != null)

{

var theSelectedText = list [0].name;

}

CRM 4.0 (Titan) Server-Side programming: Creating custom ASPX pages and

consuming Titan's Web-Services





Default.aspx.cs





I'm doing several Titan labs (CRM 4.0 labs), so I'm going to write a posting about what I'm doing. It is

always interesting archiving this kind of 'HOW TOs'.



So!, I'm gonna create a plain new custom ASPX page (using Visual Studio 2005) where we're going to

allow updates to several custom entities I've got.



The business purpose for this page would be allowing week & hours for time entry related to projects, etc.

The business purpose is not the important point in this case. What I want to show is how to create a

custom ASPX that access and updates into CRM-Titan.



First step: Creating the ASPX Page



In order to create an ASPX page, we open VS.2005 and we create a new Web-Site (normal stuff in

VS.2005). I prefer doing it in C#. 



So, within the ‘default.aspx’ page we add two combo-boxes, one for companies and another one for

projects. We also add a Table, and within that table we add several labels and textbox controls which

represent current week and hours for time entry.



The ASPX design-time (in Visual Studio 2005) would be something similar to the following:

And the HTML and Web-controls tags (ASPX code) would be something like:











CDLTLL - My custom ASPX page





























































  













So far, this is plain ASPX code, nothing about CRM-Titan, yet.



Second step: Adding CRM-Titan Web-Service References



No we start the fun part, let’s add some CRM-Titan Web-References into our WebSite project!! 



OK, first, we add a web reference to the CrmDiscoveryService (the one with AD authentication, there is

another one for Passport authentication aa well as SPLA for custom forms authentication), so the URL we

have to use is the following:



http://localhost:5555/MSCRMServices/2007/AD/CrmDiscoveryService.asmx



The ‘Add Web Reference’ window would be like:

So, what is new in this CrmDiscoveryService?. Because of CRM-Titan provides now Multi-Tenancy

(Multi-Tenancy: A single CRM server could be servicing multiple business organizations), before calling

the real ‘data-web-service’, we need to know which web-service we have to use. I mean, since each CRM

server may be serving a call for a different organization each time, the web services must be notified of

the target organization a user is intending to reach. So this CrmDiscoveryService Web-Service allows to

query all the CRM organizations on the server as well as instantiate CrmTicket credentials to allow

requests for specific organizations.



Now, we add another web reference for the updated CrmService, which has the following URL:



http://localhost:5555/MSCRMServices/2007/CrmServiceWsdl.aspx









So we have added references to the required CRM-Titan web-services using Windows integrated security

for authentication.



Third step: Writing C# Code-Behind accessing Titan’s WebServices



Now, we add some C# code within the ASPX page ‘code-behind’.



BTW, whenever you see a prefix like ‘cdltll_’ into my code, it is the CRM prefix that CRM internally

concatenates to every schema name (for columns, entities, etc.). By default, CRM adds the prefix ‘ new_’

but I prefer changing it to my own prefix (From CRM  Settings  Org.Settings  System Settings 

Customization  Prefix), which could be you company’s initials or in my case, are my own initials

(CDLTLL Cesar De La Torre Llorente). 

So!, first interesting code would be when we want to connect and get all the available organizations and

loading the that list within the ‘Organizations’ Combo-box. To do so, we should call the

CrmDiscoveryService coding something like the following:



//Instantiate web-service proxy class

CrmDiscoveryService.CrmDiscoveryService discoveryService =

new CrmDiscoveryService.CrmDiscoveryService();

//Provide current Windows/AD Credentials

discoveryService.Credentials = System.Net.CredentialCache.DefaultCredentials;



//Configure what we want to request

RetrieveOrganizationsRequest orgsRequest = new RetrieveOrganizationsRequest();



//Make request for organization information

RetrieveOrganizationsResponse orgsResponse =

(RetrieveOrganizationsResponse)discoveryService.Execute(orgsRequest);



//Loop to populate the organizations







Likewise, if we want to get the ‘project list’ (from my project custom entity), it would be something like:



CrmService.CrmAuthenticationToken token = new CrmAuthenticationToken();

token.OrganizationName = "My Organization’s Name";



CrmService.CrmService crmService = new CrmService.CrmService();

crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

crmService.CrmAuthenticationTokenValue = token;



QueryByAttribute query = new QueryByAttribute();

ColumnSet cols = new ColumnSet();

cols.Attributes = new string[] { "cdltll_projectid", "cdltll_name" };



query.ColumnSet = cols;

query.EntityName = EntityName.cdltll_project.ToString();

query.Attributes = new string[] { "ownerid" };



WhoAmIRequest userRequest = new WhoAmIRequest();

WhoAmIResponse user = (WhoAmIResponse)crmService.Execute(userRequest);



// The logged on users userid

query.Values = new object[] { user.UserId.ToString() };



BusinessEntityCollection retrievedProjects = crmService.RetrieveMultiple(query);



//Loop to populate the projects







So, with kind of this code run within my Page_Load() method, I could get data in my ASP.NET page, like

you can see down below:

Then, we can take the numbers/hours provided into the timesheet text-boxes (we should type it first, of

course. ;-)), and update my custom entity called ‘Timesheet’.



Basically, we should write this code for updating against CRM-Titan Web-Service:



// Instantiate a new timesheet entity

cdltll_timesheet timesheet = new cdltll_timesheet();



timesheet.cdltll_datesubmitted = new CrmDateTime();

timesheet.cdltll_datesubmitted.Value = DateTime.Now.ToShortDateString();



timesheet.cdltll_day1 = new CrmNumber();

timesheet.cdltll_day1.Value = Convert.ToInt32(Mon_Hours.Text);



timesheet.cdltll_day2 = new CrmNumber();

timesheet.cdltll_day2.Value = Convert.ToInt32(Tue_Hours.Text);



timesheet.cdltll_day3 = new CrmNumber();

timesheet.cdltll_day3.Value = Convert.ToInt32(Wed_Hours.Text);



timesheet.cdltll_day4 = new CrmNumber();

timesheet.cdltll_day4.Value = Convert.ToInt32(Thu_Hours.Text);



timesheet.cdltll_day5 = new CrmNumber();

timesheet.cdltll_day5.Value = Convert.ToInt32(Fri_Hours.Text);



// Set the current weeks Monday

timesheet.cdltll_startdate = new CrmDateTime();



timesheet.cdltll_projectid = new Lookup();

timesheet.cdltll_projectid.Value = new Guid(ddlProjects.SelectedValue);



timesheet.cdltll_name = ddlProjects.SelectedItem.Text + " - Timesheet submitted for " +

timesheet.cdltll_startdate.Value.ToString();

//Create de Web-Service objet-proxy

CrmService.CrmAuthenticationToken token = new CrmAuthenticationToken();

token.OrganizationName = "My Organization’s Name";

CrmService.CrmService crmService = new CrmService.CrmService();

crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

crmService.CrmAuthenticationTokenValue = token;



//Create/Update the TimeSheet within CRM-Titan

Guid timeSheetId = crmService.Create(timesheet);





So after updating, let’s say this hours (8,8,8,8,7), if we enter into CRM-Titan client, we can see it already

updated!! 









If anybody wants the whole ASP.NET page and project, just write on a comment on this posting, OK?. :-)



--> Updated. Due to many requests, I have uploaded the source code within this post. Keep in mind this

code was developed while CRM 4.0 was in BETA state. Several points could have changed.









How to call javascript functions from a custom menuitem



In the previous post we learned how to add custom menus. Now sometimes we need to call some

custom functions for some information processing. So for that we can write a javascript function

and call that javascript function from the MenuItem click.



for example: we added a MenuItem "Custom JavaScript function" at our desired entity location

and wish to call our custom function Myfunction on MenuItem click

so we need to modify the ISV.config as mentioned below:

















Now place your function in the entity onload event and expose the Myfunction function to the

page level e.g. this.Myfunction = Myfunction;







function Myfunction()

{

//Place Your logic Here...

}



this.Myfunction = Myfunction;









Now when you click on the MenuItem "Custom JavaScript function" the function Myfunction

will be called.



Labels: Microsoft CRM



posted by vishal swami @ 5:43 PM Links to this post



Adding Custom Menu items



MSCRM provides liberty to add your own CustomMenu to cater your customized needs.

for that purpose all you need to do is to edit the ISV.config file located at path /_Resources/.

This is an xml file so we can say what you all need to do is to customize this xml to suit your

needs and you are done.



To add a custom menu MSCRM provides CustomMenu tag that can be introduced in the

ISV.config at the following locations:



1. The MenuBar element inside the Grid can contain an ActionMenu element and one or

more Button elements.

2. The MenuBar element inside the Root or entity element can contain a CustomMenus

element.

Adding Action Menu Links to Grid:









































Adding Menu Links to Entities:





































Adding Menu Links to Root





























































































Do you wanna get rid of "Do you want to close this window?"



I always got this annoying question whenever i opened CRM untill I found the below mentioned

code posted by Ronald Lemmen on his blog post here , but its no more now, cheers to Ronald.

You might get a question everytime you open CRM in Internet Explorer.

The question is:

The webpage you are viewing is trying to close the window.

Do you want to close this window?

yes no

This message does appear in CRM 4.0 only when you are using

Internet Explorer 7.0 and you have enabled the application mode setting. Nevertheless, it is an

anoying message which you can get away!To get rid of this

message:

open the default.aspx file which resides in the root of the CRM website.

In this file there are these three lines of code:





var oMe = window.self;

oMe.opener =

window.self;

oMe.close();



Modify the second line of this snippet

and end up with these three lines:





var oMe =

window.self;

oMe.open('','_self','');

oMe.close();







You now will not have the message anymore.

Note:Keep in mind that any update or migration might remove this change, but you should be

able to reapply the change easily again.









CRM SDK Assemblies



The Microsoft Dynamics CRM SDK includes the following assemblies:

Microsoft.Crm.Sdk.dll

This assembly contains the base classes needed to develop custom workflows and workflow

activities. It also contains helper classes which can be used when you develop plug-ins and

workflows.

Microsoft.Crm.SdkTypeProxy.dll

This assembly contains types needed when you develop plug-ins and custom workflows. These

include the request/response classes and a set of methods that are used for instantiating CRM

types can be found in Microsoft.Crm.SdkTypeProxy.CrmTypes.

This assembly also includes the same set of entity classes, such as account class. However, these

are for internal use only. When you work with entity instances, you should use the

Microsoft.Crm.Sdk.DynamicEntity class or add the CrmService WSDL to your code and use the

entity classes found there.

See Microsoft.Crm.SdkTypeProxy Namespace for reference documentation on this assembly.

Microsoft.Crm.Outlook.Sdk.dll

This assembly contains methods and types needed for customizing Microsoft Dynamics CRM

for Microsoft Office Outlook.

See Microsoft.Crm.Outlook.Sdk Namespace for reference documentation on this assembly.

Microsoft.Crm.Tools.EmailProviders.dll

This assembly contains methods and types needed for developing a custom E-mail Provider

component for the Microsoft Dynamics CRM E-mail Router.

See Microsoft.Crm.Tools.Email.Providers Namespace for reference documentation on this

assembly.

Both 32-bit and 64-bit versions of these assemblies can be found in the SDK\Bin folder of the

SDK download. The download is located at go.microsoft.com/fwlink/?LinkID=102966.

If you are running in a 32-bit process, use the 32-bit assemblies. If you are running in a 64-bit

process, use the 64-bit assemblies.

For synchronous plug-ins, use the version that matches the Microsoft Dynamics CRM server.

For custom workflow activities and asynchronous plug-ins, use the version that matches the

Asynchronous service.

For client applications and add-ins, use the version that matches the Web application or

Microsoft Dynamics CRM for Outlook.

For Microsoft Dynamics CRM Online, use the version that matches the Web application or

Microsoft Dynamics CRM for Outlook.









CRM 4.0 delete Organization



some time back I created an organization in our CRM server for a client but after some time we

were told to remove the organization. I searched everywhere in the deployment manager but

found no option to do the same. The only option I got there was to disable the organization. I

scratched my head try almost all the links but of no use, so finally I disabled the organization.

few days back i discussed the same with one of my friend Naren about the same he also did the

full research in the deployment manager and YESSSSS he found the way. All we need to do is to

first disable the organization and then we got the option to re enable it or delete it. the only thing

now we need to remember is that this delete operation does not delete the org_MSCRM database

, you have to delete the same manually.







How to Increase the Tab limit in CRM Forms



just browsing the net and i found this beautiful post regarding tab limits in CRM forms ,

originally posted here



Hats off to the original contributor.



hope its useful for the readers.



By default the max number of tabs allowed in CRM Form is 8.

The max tab limit is defined in JavaScript of formeditor.aspx. This page can be found at the

following location “\Microsoft Dynamics CRM\CRMWeb\Tools\FormEditor”.

You can change the count specified in the _iMaxTabs to increase the count as shown in the

below screenshot.









Note: This is an unsupported change and it could be overwritten if you install Rollups for

CRM.

How to read the record selection from the ISV buttons added to the Grid



The buttons added to the CRM grids allow the user to select multiple records from the Grid and

perform the said operation on all the selected records.



It is very easy to add a button on an entity grid. You need to add the button tag to the Grid

section as explained below. It is important that for the selected record information to be passed

on to the receiving page, the page should be displayed in a Modal window. Hence the Winmode

for the button should be “2”



























Now, we need to be able to read the record selection from the grid on the custom page. The

record selection is passed to the receiving page as a comma separated list of entityid’s of the

selected records from the grid. This is enclosed in the tags.



If you want to read the information through server-side code you can read it using

Request.InputStream.



StreamReader sr = new StreamReader(Request.InputStream);

string recordIds = sr.ReadToEnd();





Since it is enclosed in tag it can be read as XML string

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(recordIds);

selectedEntities = xmlDoc.DocumentElement.InnerText;



and the information then split by comma to extract the list of ids.

return selectedEntities.Split(new char[] { ',' });



If you want to read this information from client side through jscript… you will get the id using

window.dialogArguments and then you can perform the same operations as above.

Retrieve Marketing List Members

A Marketing list in CRM, can be a collection accounts or contacts or leads. Retrieving the

members of a marketing list is not as as simple. We just realized that the list member entity

only stores the link to the entity and Retrieve method is not supported by this entity.



Hence to retrieve the list members for a given entity we need to identify the type of entity

being supported by the list i.e Leads/Accounts/Contacts and then using the link entity

functionality link it with the listmember entity to get the list.



Following is the snippet of getting collection of accounts from a particular marketing list id.



//initialize QueryExpression for adding link entities

QueryExpression qe = new QueryExpression();

qe.EntityName = EntityName.account.ToString();

//Initialize columnset

ColumnSet col = new ColumnSet();



//add columns to columnset for the acc to retrieve each acc from the acc list

col.AddColumns(new string[] { "accountid", "name", "address1_line1", "address1_line2",

"address1_city", "address1_stateorprovince", "address1_postalcode"});



qe.ColumnSet = col;



// link from account to listmember

LinkEntity le = new LinkEntity();

le.LinkFromEntityName = EntityName.account.ToString();

le.LinkFromAttributeName = "accountid";

le.LinkToEntityName = EntityName.listmember.ToString();

le.LinkToAttributeName = "entityid";



//link from listmember to list

LinkEntity le2 = new LinkEntity();

le2.LinkFromEntityName = EntityName.listmember.ToString();

le2.LinkFromAttributeName = "listid";

le2.LinkToEntityName = EntityName.list.ToString();

le2.LinkToAttributeName = "listid";



// add condition for listid

ConditionExpression ce = new ConditionExpression();

ce.AttributeName = "listid";

ce.Operator = ConditionOperator.Equal;

ce.Values = new object[] { strList };//here “strList” is the marketing list id provided to this

function.



//add condition to linkentity

le2.LinkCriteria = new FilterExpression();

le2.LinkCriteria.Conditions.Add(ce);

//add linkentity2 to linkentity

le.LinkEntities.Add(le2);



//add linkentities to Query Expression which is passed for getting collection of accounts

qe.LinkEntities.Add(le);



//above query expression is passed to retrieve multiple for getting BusinessEntityCollection

of accounts.

BusinessEntityCollection bec = service.RetrieveMultiple(qe);



Similarly you could link with Contacts/Leads to get the list of members from a Contact/Lead

Marketing list.









http://justgeeks.blogspot.com/2010/01/how-to-query-microsoft-dynamics-crm.html







http://translate.googleusercontent.com/translate_c?hl=en&sl=zh-CN&u=http://www.winu.cn/space-

14160-do-blog-id-

26067.html&prev=/search%3Fq%3DCrmServiceWsdl.aspx%253F%26start%3D90%26hl%3Den%26sa%3D

N%26prmd%3Db&rurl=translate.google.co.in&usg=ALkJrhhEiv6snGJFe4VNEbbaaSIKYwKegw







http://blogs.msdn.com/b/cesardelatorre/archive/2007/08/09/crm-titan-server-side-programming-

creating-aspx-pages-and-consuming-titan-s-web-services.aspx?PageIndex=2







http://translate.googleusercontent.com/translate_c?hl=en&sl=zh-CN&u=http://www.winu.cn/space-

14160-do-blog-id-

26067.html&prev=/search%3Fq%3DCrmServiceWsdl.aspx%253F%26start%3D90%26hl%3Den%26sa%3D

N%26prmd%3Db&rurl=translate.google.co.in&usg=ALkJrhhEiv6snGJFe4VNEbbaaSIKYwKegw


Related docs
Other docs by Trinadh Kumar ...
MS CRM RESUME.
Views: 32  |  Downloads: 0
Interview_Questions
Views: 1  |  Downloads: 0
Ajax Interview Questions
Views: 1  |  Downloads: 0
C_
Views: 1  |  Downloads: 0
Introduction to the Spring Framewor
Views: 6  |  Downloads: 0
Spring_Examples
Views: 6  |  Downloads: 0
MS CRM
Views: 6  |  Downloads: 0
Hibernate Presentation
Views: 1  |  Downloads: 0
designpatterns
Views: 3  |  Downloads: 0
ASP.NET
Views: 5  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!