Wednesday, September 30, 2009

Create log - first option in Event Viewer

Hi,

There are several options for writing logs

1. Create log in event viewer
2. Create log in file
3. Create log in entity log

Here is an example of writing log in event viewer


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace WriteToEventLog {
class Program {
static void Main(string[] args) {
string eventViewerName = "EventViewerName";
string sourceName = "Project name";
string message = "My Message";

if (!EventLog.SourceExists(sourceName))
EventLog.CreateEventSource(sourceName, eventViewerName);

EventLog.WriteEntry(sourceName, message);
EventLog.WriteEntry(sourceName, message, EventLogEntryType.Warning, 1100);
EventLog.WriteEntry(sourceName, message, EventLogEntryType.Error,45454);
}
}
}


Thanks
Rami Heleg.

Friday, September 25, 2009

Problem:
Running server-side code developments under CRM Server folder get Error 401 – Unauthorized.

This is a problem I've seen several times.
if you try to run the same code not under CRM folder and it works fine here is the Solution:

To solve this error need to make change in Microsoft CRM 4.0 web config:

What to add:










Thanks,
Rami Heleg

CRM Screens freeze- Stuck

Try to open CRM Form usually edit.aspx page with a few iframes.

in some cases screen Stuck.

The reason for that is internet explorer Settings.
The default connection for internet explorer is two. It means the main form request data + one of the iframes then other iframes wait.. this problem Causes CRM to be freeze.

Solution:
Change the default values:
Open register page:
1. Go to start - > run and Type regedit:
2. Define MaxConnectionsPer1_0Server and MaxConnectionsPerServer like the following example


[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings] MaxConnectionsPer1_0Server = dword: 0000000a
MaxConnectionsPerServer = dword: 0000000a





Thanks,

Rami Heleg

Tuesday, September 22, 2009

Update entity Based Micorost CRM SDK

Hi,
This example used to update record in crm 3.0 and crm 4.0 based SDK

//Create crm service
CrmService pService = new CrmService(); // optional to set url

// define entity + fields. mandatory field is key
incident oInc = new incident();
oInc.incidentid = new Key();
oInc.incidentid.Value = new Guid("guid");
oInc.title="my title"

pService.Update(oInc);

update Can get specific entity for instance contact, incident or dynamic entity.
all type of BusinessEntity.

thanks,
Rami Heleg

Monday, September 21, 2009

Create Entity Based Microsoft CRM SDK

Hi,
this example used to create a new record in crm 4,3 based CRM SDK.

//Create CRM Service
CrmService pService = new CrmService(); // optional to set url BusinessEntity

//Define entity and add values..
contact oContact = new contact();
oContact.firstname = "Rami";
oContact.lastname = "Heleg";

//Run method to create the entity.
Guid guid = pService.Create(entity);
//guid of the new record.


Thanks,
Rami Heleg

Using SDK to delete entity record via Dynamic entity

This Example help to delete record using SDK function.

DeleteRequest request = new DeleteRequest();
TargetDeleteDynamic target = new TargetDeleteDynamic();
target.EntityName = entityTypeName;
target.EntityId = instanceID;
request.Target = target;
pservice.Execute(request);

Enjoy,
Rami Heleg

RetrieveMultipleResponse - Query example.

Example of query on server side.

//Create Condition.. can be many conditions + type of operator
ConditionExpression[] conditions = new ConditionExpression[1];
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = fullname;
condition.Operator = ConditionOperator.Equal;
condition.Values = new object[] { "Rami Heleg" };
conditions[i] = condition;
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = conditions;
QueryExpression query = new QueryExpression();

//Entity name
query.EntityName = "contact";

//allow to define specific columns
query.ColumnSet = new AllColumns();
query.Criteria = filter;
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.ReturnDynamicEntities = false;
request.Query= query ;
//run Query
RetrieveMultipleResponse response = (RetrieveMultipleResponse)pService.Execute(service, request);
//Result
response.BusinessEntityCollection.BusinessEntities;

Thanks,
Rami Heleg

Tuesday, September 15, 2009

View Schema via internet explorer

Hi,

Here is an example how to view schema information via internet explorer

http://servername:port/org_name/sdk/list.aspx

enable to view entities, attributes and relationships.

Thanks,
Rami Heleg

function to return on server side information regarding current system user.

Example of WhoAmI for Microsoft Dynamic CRM 4.0

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "OrganizationName";

CrmService pService = new CrmService(); // optional to set url parameter
pService.CrmAuthenticationTokenValue = token;
pService.Credentials = CredentialCache.DefaultCredentials;

WhoAmIRequest request = new WhoAmIRequest();

WhoAmIResponse oSystem= (WhoAmIResponse)pService.Execute(request);
//oSystem.UserId;
//oSystem.OrganizationId ;//

Thanks,
Rami Heleg.

Monday, September 14, 2009

Example function to Set State for Dynamic entity

You can use Set State function for each entity for instance:
SetBusinessSystemUserRequest
SetAccountUserRequest
SetContactUserRequest and more.
Better is to create general function and use dynamic request
Example:
SetStateDynamicEntityRequest request = new SetStateDynamicEntityRequest();
request.Entity = new Moniker();
request.Entity.Name = entityTypeName;
request.Entity.Id = new Guid ( guid);
request.State = relevantStateCodeForSpecificEntity;
request.Status = relevantStatusForSpecificEntity;
service.Execute(request);

Enjoy,
Rami Heleg

Saturday, September 12, 2009

Change Maximum tabs

Hi,

CRM limit the number of tabs to 8.

To change the number:

C:\Program Files\Microsoft CRM Server\CRMWeb\Tools\FormEditor\formeditor.aspx

Need to change the parameter _iMaxTabs to required number.

Enjoy,
Rami Heleg

Shrink Javascript file

to improve performance one of the options is to shrink Javascript file.
link to site that help you to shrink the file and save 30 % from file size
http://www.creativyst.com/Prod/3/.

Recommended to do it before moving to production

Thanks,
Rami Heleg

Call from Javascript to Server via WCF/Json

Here is a simple example of calling to server from javascript side

1. create a new project name = 'WCFJson'
2. add new html page call HTMLPage.htm.
3. paste code to javascript:

var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
var url = "http://localhost/WCFJson/Service.svc/rami/isExist";
var body = '{"name":"'+ "ramigggg" + '"}';
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send(body);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4){
alert( xmlHttp.responseText);
}
}

4. create new wcf service name 'Service.svc'
5. paste code the interface file


[ServiceContract]
public interface IService{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/isExist")]
bool isExist(string name);
}

6. paste code to service file


public class Service : IService
{
#region IService Members
public bool isExist(string name) {
return true;
}
#endregion
}

7. runproject when html file the the startup page....

good luck,
Rami Heleg

Attach event CRM Field

Here is an example to attach event to CRM Field

Function:

Function attachEvent (elementID, eventName, handler){
var obj =document.getElementById(elementID);
if (!element)
return;
element.attachEvent(eventName, handler);
}

Call Example:
attachEvent ('firstname’, 'onchange', handleFirstNameChanged);

Enjoy,
Rami Heleg

Set mandatory to CRM fields

Hi,
Here is the function to set mandatory to CRM field in Javascript

crmForm.SetFieldReqLevel(fieldName, value);

SetFieldReqLevel get 2 parameters

1. field name like firstname,createdon etc...
2. second parameter true,false.

Enjoy,
Rami Heleg

Thursday, September 10, 2009

Hot to get page name in crm,js

Hi,
Here is an example how to get page name.

function GetPageName() {
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
return sPage;
}

Rami Heleg,

Lookup Field properties

Hi,
here is the properties for lookup field in JS side

var parentIncident= new Array;
parentIncident = null;

parentIncident = crmForm.all.parentincident.DataValue;

if (parentIncident[0] != null)
{
//description
var desc = parentIncident[0].name;

//Guid
var incidentId = parentIncident[0].id;

// Object Type
var type = parentIncident[0].typename;

}

Enjoy,
Rami Heleg

crmForm, Field properties

Some words regarding field ( javascript side in crm)

to get field from crm page can by via two options:

1.
var firstName = crmForm.all.firstname;
2.
var firstName= document.getElementById('firstname'); //faster

properties + events:

1. firstName.SetFocus();
set focus on field.

2. firstName.IsDirty
true/false if field changed.

3. firstName.RequiredLevel
0 == normal
1 == recommended
2 == required

4. firstName.DataValue
set/get value from field.

5. firstName.ForceSubmit
send field value to server on save any way


Enjoy,
Rami Heleg.

crmForm Property

Here some words regarding crmForm properties

1. crmForm.IsDirty
if user change field in page IsDirty = true
2. crmForm.ObjectTypeName
return object name account,contact etc...
3. crmForm.ObjectTypeCode
return object key 1,2,112 etc.

Rami Heleg

crmForm FormType options

Hi,
this comment for form type - mode for edit page.

crmForm.FormType return form type/mode
1 = Create
2 = Update
3 = Read Only
4 = Disabled
5 = Quick Create
6 = Bulk edit ( After select multi records and choose from menu to create...


Rami Heleg,

Reading from webconfig/app config

Example how to read from web config

1. add using to page
using System.Configuration;Enjoy,
2. read from config file
string value= ConfigurationSettings.AppSettings["key"];

Enjoy,
Rami Heleg

Create Crm Service example based systemuser and organization

Here function to create Crm Service example for specific systemuser and organization name

public static CrmService GetCrmService(Guid callerID,string organizationName) {
CrmService rslt = new CrmService();
rslt.Url = "http://localhost:5555/MSCRMServices/2007/CrmService.asmx";
CrmServiceSdk.CrmAuthenticationToken token = new CrmServiceSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = organizationName;
token.CallerId = callerID;
rslt.CrmAuthenticationTokenValue = token;
rslt.Credentials =CredentialCache.DefaultCredentials;
return rslt;
}

Enjoy,
Rami Heleg

Create Metadata Service example

here function to create crmService based organization Name.

public static MetadataService GetMetadataService(string organizationName) {
MetadataService metadata = new MetadataService();
metadata.Url = "http://localhost:5555/MSCRMServices/2007/CrmService.asmx";
MetadataServiceSdk.CrmAuthenticationToken token = new MetadataServiceSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = organizationName;
metadata.CrmAuthenticationTokenValue = token;
metadata.Credentials =CredentialCache.DefaultCredentials;
return metadata;
}

Enjoy,
Rami heleg

Create CrmService example

here function to create crmService based organization Name.

public static CrmService GetCrmService(string organizationName) {
CrmService rslt = new CrmService();
rslt.Url = "http://localhost:5555/MSCRMServices/2007/CrmService.asmx";
CrmServiceSdk.CrmAuthenticationToken token = new CrmServiceSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = organizationName;
rslt.CrmAuthenticationTokenValue = token;
rslt.Credentials =CredentialCache.DefaultCredentials;
return rslt;
}

Enjoy,
Rami heleg

Set Value to Dynamic entity

Microsoft.Crm.Sdk.DynamicEntity entity

//Set value to CrmNumber
Microsoft.Crm.Sdk.CrmNumber number = new Microsoft.Crm.Sdk.CrmNumber();
number.Value = ToInt(propertyValue);
entity.Properties[propertyName] = number;

//Set Value to String
entity.Properties[propertyName] = propertyValue.ToString();


Enjoy,
Rami Heleg

Monday, September 7, 2009

SetMandatory

Hi,
Function to set mandtory true/false in CRM 4.0

this.setMandatory = function(fieldName, value) {
crmForm.SetFieldReqLevel(fieldName, value);
}

Enjoy,
Rami heleg