Showing posts with label Server Side. Show all posts
Showing posts with label Server Side. Show all posts

Monday, October 11, 2010

Use Thread to improve performance.

Option to improve performance for callouts or just server side is to use thread

Here Is an example of using thread:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace thread {

class Program {
static void Main(string[] args) {
  System.Threading.ThreadPool.QueueUserWorkItem(f => {xxx();});
  }

  static void xxx(){
  int a = 8;
  }
 }
}



Enjoy,

Rami Heleg

Monday, August 16, 2010

Get CrmService for specific organization.

I have many organizations and I need the entities for specific organization

The solution


Create crm service where URL contain
?uniquename=org_name

for instance:
http://servername/MSCRMService/2007/Crmservice.asmx/?uniquename=org_name
enjoy,
Rami Heleg

Sunday, July 18, 2010

How to find which Rollup CRM installed?

I installed some rollups.

i want to know if i installed specific version

1. open control panel/ installed updated and check which version like next picture



2. if you see only KBXXX go to crm download rollup center and check the rollup id like this pictures



thanks,
Rami Heleg.

Sunday, April 18, 2010

Remove Outlook button in Microsoft dynamics CRM

Hi,
after installed rollup 7 to CRM new button appear " Outlook"

to remove this button:

1. On the Microsoft Dynamics CRM Application Server click Start, click Run, type Regedit, and then click OK.

2. Locate the following registry subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM.

3. Right-click MSCRM, click New, and then click DWORD (32-bit) Value.
Name the new key DisableOutlookSetupLink.

4. Right-click DisableOutlookSetupLink, click Modify, and then type 1 to disable the CRM for Outlook button for all users.

thanks
Rami heleg

Tuesday, December 22, 2009

How to init Value on Server side

This example contain how to init all CRM Values:
CrmDateTime lDateTime = new CrmDateTime("2009/8/27T17:00:00");

CrmBoolean lBoolean = new CrmBoolean(true);

Picklist lList = new Picklist(1);

CrmDecimal lDec = new CrmDecimal(10.1);

CrmFloat lfloat = new CrmFloat(10.2);

CrmNumber lNumber = new CrmNumber(10);

Lookup oSys = new Lookup("systemuser", userId);

Owner owner = new Owner("systemuser", systemUserId);

Status lStatus = new Status(1);

EntityNameReference oReference = new EntityNameReference("systemuser");

Key key = new Key(userId);

CrmMoney lMoney = new CrmMoney(10.00);

Enjoy,
Rami Heleg

Thursday, December 3, 2009

How to change due date filter default value for activities page:


Sometimes you need to define your default filter values for the home activities page.


Here is an example how to change due date filter default value:

Add this code to "\CRMWeb\Workplace\home_activities.aspx" page:

<script runat="server">
protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
this.crmDateSelector.Selected = "Today";
this.crmGrid.Parameters.Add("scheduledend", "Today");
}
</script>

You can set these values to the crmDateSelector control:
Overdue
Today
Tomorrow
NextXDays;7
NextXDays;30
NextXDays;90
NextXMonths;6
NextXMonths;12
All

thanks,
Max Shafranski,
Team blog member.

Tuesday, November 17, 2009

Create Annotation with File

Here is an example to create Annotation:

annotation n = new annotation();

n.objectid = new Lookup();
//define to which entity
n.objectid.Value = new Guid(EntityId);
attach to specific entity
n.objecttypecode = new EntityNameReference();
n.objecttypecode.Value = EntityType;

//Create
Guid noteID = pService.Create(n);

//open and read file
FileInfo file = new FileInfo(fileP);
FileStream fs = file.OpenRead();
byte[] byteData = new byte[fs.Length];
fs.Read(byteData, 0, byteData.Length);
fs.Close();

string encodedData = System.Convert.ToBase64String(byteData);

//Create the Request Object
UploadFromBase64DataAnnotationRequest upload = new
UploadFromBase64DataAnnotationRequest();

//Set the Request Object's Properties
upload.AnnotationId = noteID;
upload.FileName = file.Name;
upload.MimeType = "text/plain";
upload.Base64Data = encodedData;

//Execute the Request
UploadFromBase64DataAnnotationResponse uploaded =
(UploadFromBase64DataAnnotationResponse)pService.Execute(upload);


Entity contain annotation + file.

enjoy,
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

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

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

Thursday, September 10, 2009

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

Friday, August 7, 2009

Function to get value from dyanamic entity field

public static Guid GetKeyValue(Microsoft.Crm.Sdk.DynamicEntity de, string val)
{
foreach (KeyProperty ent in de.Properties)
{
if (ent.Name == val)
return ent.Value.Value;
}
return Guid.Empty;

}

Enjoy,
Rami Heleg

Function to get value from dyanmic entity

public static string GetValueFromProperty(object property)
{
switch (property.GetType().Name)
{
case "String":
return ((String)property);
case "Lookup":
return ((Microsoft.Crm.Sdk.Lookup)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Lookup)property).Value.ToString();
case "Picklist":
return ((Microsoft.Crm.Sdk.Picklist)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Picklist)property).name.ToString();
case "Customer":
return ((Microsoft.Crm.Sdk.Customer)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Customer)property).name.ToString();
case "CrmNumber":
return ((Microsoft.Crm.Sdk.CrmNumber)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmNumber)property).Value.ToString();
case "CrmFloat":
return ((Microsoft.Crm.Sdk.CrmFloat)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmFloat)property).Value.ToString();
case "CrmMoney":
return ((Microsoft.Crm.Sdk.CrmMoney)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmMoney)property).Value.ToString();
case "CrmBoolean":
return ((Microsoft.Crm.Sdk.CrmBoolean)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmBoolean)property).Value ? "1" : "0";
case "CrmDateTime":
return ((Microsoft.Crm.Sdk.CrmDateTime)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.CrmDateTime)property).Value;
case "Status":
return ((Microsoft.Crm.Sdk.Status)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Status)property).Value.ToString();
case "State":
return "0";
case "Key":
return ((Microsoft.Crm.Sdk.Key)property).Value.ToString();
case "Owner":
return ((Microsoft.Crm.Sdk.Owner)property).IsNull == true ? "" : ((Microsoft.Crm.Sdk.Owner)property).name.ToString();
}
return "";
}

Enjoy,
Rami Heleg