Friday, March 19, 2010

Retrieve Entity using ConditionExpression,FilterExpression,QueryExpression

ConditionExpression condtionToGetCase = new ConditionExpression();

// Set the ConditionExpressions Properties so that the condition is true when
// the incidentid or the incident/case is equal to incidentid.
condtionToGetCase.AttributeName = "incidentid";
condtionToGetCase.Values = new string[] { EntityID.ToString() };
condtionToGetCase.Operator = ConditionOperator.Equal;
// Create the FilterExpression.
FilterExpression filterToGetCase = new FilterExpression();
// Set the properties of the FilterExpression.
filterToGetCase.FilterOperator = LogicalOperator.And;
filterToGetCase.Conditions.Add(condtionToGetCase);
// Create a column set that holds the names of the columns to be retrieved.
ColumnSet colsToGetCustomer = new ColumnSet();
colsToGetCustomer.AddColumn("title");
colsToGetCustomer.AddColumn("customerid");
// Create the QueryExpression.
QueryExpression queryToGetCase = new QueryExpression();
// Set the properties of the QueryExpression.
queryToGetCase.EntityName = EntityName.incident.ToString();
queryToGetCase.ColumnSet = colsToGetCustomer;
queryToGetCase.Criteria = filterToGetCase;
// Retrieve the cases/incidents.
BusinessEntityCollection cases = serviceSdk.RetrieveMultiple(queryToGetCase);
//Retrieve the case/incident.
if (cases.BusinessEntities.Count > 0)
{
regradingObject = (incident)cases.BusinessEntities[0];
}

Retrieve Dynamic Entity by entityid using sdk

// Create the retrieve target.
TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();
// Set the properties of the target.
targetRetrieve.EntityName = EntityName.appointment.ToString();
targetRetrieve.EntityId = EntityID;
// Create the request object.
RetrieveRequest retrieve = new RetrieveRequest();
// Set the properties of the request object.
retrieve.Target = targetRetrieve;
// Create a column set that holds the names of the columns to be retrieved.
ColumnSet colsToGetAppointment = new ColumnSet();
colsToGetAppointment.AddColumn("subject");
colsToGetAppointment.AddColumn("scheduledstart");
colsToGetAppointment.AddColumn("regardingobjectid");
retrieve.ColumnSet = colsToGetAppointment;
// Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
retrieve.ReturnDynamicEntities = true;
// Execute the request.
RetrieveResponse retrieved = (RetrieveResponse)serviceSdk.Execute(retrieve);
// Extract the DynamicEntity from the request.
appointmentDyn = (DynamicEntity)retrieved.BusinessEntity;

To retrieve dynamic entity in Create and Update Plugin

// Check if the input parameters property bag contains a target
// of the create operation and that target is of type DynamicEntity.
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
// Obtain the target business entity from the input parmameters.
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
}
else
{
throw new InvalidPluginExecutionException("Invalid Context");
}

Wednesday, March 17, 2010

To get instanceid for appoitment in post update plugin

if (context.InputParameters.Properties.Contains("Target") &&

context.InputParameters.Properties["Target"] is DynamicEntity)
{

DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties["Target"];
Guid instanceID = ((Key)entity.Properties["activityid"]).Value;

}


for reference

http://www.patrickverbeeten.com/pages/ContentItemPage.aspx?id=12&item=53&p=true

http://nishantrana.wordpress.com/2009/01/21/understanding-inputparameters-and-outputparameters-of-plugin-context-in-crm40/

To get instance id for each type of event in plugin for crm 4.0

Massage name “Create”:

Guid instanceID = new Guid(context.OutputParameters.Properties["id"].ToString());

Massage name “Update”:
Guid instanceID = (Guid)((Microsoft.Crm.Sdk.Key)((Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters.Properties["Target"]).Properties[context.PrimaryEntityName + "id"]).Value;

Massage name “SetState”:
Guid instanceID = new Guid(context.OutputParameters.Properties["id"].ToString());

Massage name “Assign”:
Guid instanceID = vInstanceID = (Guid)((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["Target"]).Id;

Massage name “Delete”:
instanceID = ((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["Target"]).Id;

Massage name “Close”:
Guid instanceID = ((Microsoft.Crm.Sdk.Lookup)((Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters.Properties["IncidentResolution"]).Properties[context.PrimaryEntityName + "id"]).Value;

Massage name “Route”:
Guid instanceID = ((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["Target"]).Id;

Massage name “SetStateDynamicEntity”:
Guid instanceID = ((Microsoft.Crm.Sdk.Moniker)context.InputParameters.Properties["EntityMoniker"]).Id;

Tuesday, March 16, 2010

To open microsoft dynamics crm in a browser window without menu, navigation and command bars

go to
settings-->Administration--->System Settings--->Customization
check
Open Microsoft Dynamics CRM in  Application mode

The identity of application pool 'Test Pool' is invalid, so the World Wide Web Publishing Service can not create a worker process to serve the application pool. Therefore, the application pool has been disabled.

was actually trying to add a system account to the identity of apppool of crm website but got the error
found the support article to fix this but did not used it.
http://support.microsoft.com/kb/929388

instead of that gone ahead with using network service itself

in the process also read what are these windows accounts


LocalService:
The LocalService account is a predefined local account used by the service control manager. This account is not recognized by the security subsystem, so you cannot specify its name in a call to the LookupAccountName function. It has minimum privileges on the local computer and presents anonymous credentials on the network.


This account can be specified in a call to the CreateService function. Note that this account does not have a password, so any password information that you provide in this call is ignored. While the security subsystem localizes this account name, the SCM does not support localized names. Therefore, you will receive a localized name for this account from the LookupAccountSid function, but the name of the account must be NT AUTHORITY\LocalService when you call CreateService, regardless of the locale, or unexpected results can occur.

NetworkService Account


The NetworkService account is a predefined local account used by the service control manager. This account is not recognized by the security subsystem, so you cannot specify its name in a call to the LookupAccountName function. It has minimum privileges on the local computer and acts as the computer on the network.

This account can be specified in a call to the CreateService function. Note that this account does not have a password, so any password information that you provide in this call is ignored. While the security subsystem localizes this account name, the SCM does not support localized names. Therefore, you will receive a localized name for this account from the LookupAccountSid function, but the name of the account must be NT AUTHORITY\NetworkService when you call CreateService, regardless of the locale, or unexpected results can occur.

A service that runs in the context of the NetworkService account presents the computer's credentials to remote servers. By default, the remote token contains SIDs for the Everyone and Authenticated Users groups. The user SID is created from the SECURITY_NETWORK_SERVICE_RID value.

LocalSystem Account


The LocalSystem account is a predefined local account used by the service control manager. This account is not recognized by the security subsystem, so you cannot specify its name in a call to the LookupAccountName function. It has extensive privileges on the local computer, and acts as the computer on the network. Its token includes the NT AUTHORITY\SYSTEM and BUILTIN\Administrators SIDs; these accounts have access to most system objects. The name of the account in all locales is .\LocalSystem. The name, LocalSystem or ComputerName\LocalSystem can also be used. This account does not have a password. If you specify the LocalSystem account in a call to the CreateService function, any password information you provide is ignored.

A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account. This has several implications:

The registry key HKEY_CURRENT_USER is associated with the default user, not the current user. To access another user's profile, impersonate the user, then access HKEY_CURRENT_USER.

The service can open the registry key HKEY_LOCAL_MACHINE\SECURITY.

The service presents the computer's credentials to remote servers.

If the service opens a command window and runs a batch file, the user could hit CTRL+C to terminate the batch file and gain access to a command window with LocalSystem permissions.

The NetworkService account has its own subkey under the HKEY_USERS registry key. Therefore, the HKEY_CURRENT_USER registry key is associated with the NetworkService account.

Enum Code

public enum MyEnum

{

Enum1 = 1,

Enum2 = 2

}

Monday, March 15, 2010

sql database code and connection

today after long time did sql database code .



string conStr = "Data Source=server;Initial Catalog=Database;Integrated Security=SSPI;"
string conStr = "Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"

SqlConnection con = new SqlConnection(conStr);
con.Open();
string cmdText = "storedProc";
SqlCommand cmd = new SqlCommand(cmdText,con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@param", SqlDbType.VarChar);
param.Value = "";
cmd.Parameters.Add(param);
int result = cmd.ExecuteNonQuery();

Guys do you also use the same code or have come with some new pattern oriented code

Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope

problem:
I added webreference for crmservice
http://server/mscrmservices/2007/crmservice.asmx?wsdl&uniquename=organization
and it redirected to
http://server/mscrmservices/2007/crmservicewsdl.aspx?uniquename=organization
thats how crmservice works
but when using CrmService.Retrieve method i got the error

"Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope"

solution:
when setting url property CrmService service
we should use
http://server/mscrmservices/2007/crmservice.asmx?wsdl&uniquename=organization
and not
http://server/mscrmservices/2007/crmservicewsdl.aspx?uniquename=organization

we will not get that error

Sunday, March 14, 2010

Brain registry

Have started working on this project.
needs .
will upload the source code over here