Dynamics 365

Execute Workflow using Web API in Dynamics 365

Execute Action using Web API in Dynamics 365

CRM and Azure Integration – Part 1

Debug WCF Restful service (POST/GET) – Part 2

 


CRM 3.0/CRM 4.0/ CRM 2011

Blank.aspx issue with IE 6.0 for CRM 4.0

If you are getting a dialog box asking to download Blank.aspx in every pop-up window in the CRM then this article is for u.

Recently, a KB cumulative hotfix (KB953838)from windows update has apparently damaged the aspx association link within Internet Explorer 6.

http://support.microsoft.com/kb/953838

If you’re seeing this issue, you can resolve the problem in either the following ways:

1) Try to first save Blank.aspx as a file to your desktop.  Right-click on it, and choose to open with ‘Internet Explorer’.  Make sure to check on ‘always use this…’  Failing this try either of the following:
2) Uninstall the KB patch from the user’s Add/Remove Programs
3) Install Internet Explorer 7 overtop of IE 6
4) Remote into the CRM server, and open Blank.aspx in notepad.  (note: Blank.aspx can be found in: My Computer -> Program Files -> Microsoft Dynamic CRM -> CRMWeb -> _root -> Blank.aspx
On the header of Blank.aspx, add the word test and save Blank.aspx.  Restart IIS, and then clear the temporary internet files of the user with the issue.

Try on of above which suits u most.

 

Warning message in event log for ASP.NET: The request has been aborted

We were getting following warning message in event log
Event code: 3001
Event message: The request has been aborted.
Event time: 3/5/2010 11:49:45 PM
Event time (UTC): 3/5/2010 6:19:45 PM
Event ID: b77a7fa86dda49eead52978a8d655d6e
Event sequence: 33152
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/3/ROOT-1-129122820495000000
Trust level: Full
Application Virtual Path: / Application Path: D:\Program Files\Microsoft Dynamics CRM\CRMWeb\

Machine name: <MachineName>
Process information:
Process ID: 2916
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:
Exception type: HttpException
Exception message: Request timed out.

Request information:
Request URL: http://CrmServer:5555/<Org_Name>/Workplace/home_activities.aspx         Request path: /<Org_Name>/Workplace/home_activities.aspx
User host address: IP Address
User: domain\username
Is authenticated: True
Authentication Type: Negotiate
Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:
Thread ID: 9
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace:

Custom event details:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Solution:

Increasing the request execution timeout for ASP.NET solved the problem.
Steps to modify execution timeout
1. Go to IIS Manager.
2. Select Web Sites -> Microsoft Dynamics CRM
3. Right Click ->Properties
4. Select ASP.NET Tab
5. Click on Edit Configuration
6. Select Application Tab
7. Set Request execution time=1200(default is 300)
8. Click ok two times.
9. Close the IIS Manager.

This solved our problem.

Sharing records with user/team

//Set up the CRM Service.

CrmAuthenticationToken token = new CrmAuthenticationToken();

// Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = “AdventureWorksCycle”;
CrmService service = new CrmService();
service.Url = “http://<servername>:<port>/mscrmservices/2007/crmservice.asmx”;
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the SecurityPrincipal Object
SecurityPrincipal principal = new SecurityPrincipal();
principal.Type = SecurityPrincipalType.User;

// PrincipalId is the Guid of the user to whom access is being granted
principal.PrincipalId = new Guid(“7B222F98-F48A-4AED-9D09-77A19CB6EE82”);

// Create the PrincipalAccess Object
PrincipalAccess principalAccess = new PrincipalAccess();

// Set the PrincipalAccess Object’s Properties
principalAccess.Principal = principal;

// Gives the principal access to read
principalAccess.AccessMask = AccessRights.ReadAccess;

// Create the Target Object for the Request
TargetOwnedAccount target = new TargetOwnedAccount();

// EntityId is the Guid of the account access is being granted to
target.EntityId = new Guid(“6A92D3AE-A9C9-4E44-9FA6-F3D5643753C1”);

// Create the Request Object
GrantAccessRequest grant = new GrantAccessRequest();

// Set the Request Object’s properties
grant.PrincipalAccess = principalAccess;
grant.Target = target;

// Execute the Request
GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grant);

<!--[endif]-->

Display Associate View in IFrame 
/**********  IFrame Onload *****************/

if(crmForm.FormType !=1)

{

var pPFrame = document.all.IFRAME_ProductPurchase;

var pPWindow = document.frames[‘IFRAME_ProductPurchase’];

document.all.IFRAME_ProductPurchase.src=”/userdefined/areas.aspx?oId=” + crmForm.ObjectId + “&oType= ” + crmForm.ObjectTypeCode + “&security=” + crmFormSubmit.crmFormSubmitSecurity.value + “&tabSet=mul_contact_mul_customerproductpurchase”;

pPFrame.name = pPFrame.id;

pPFrame.style.borderWidth = ‘0px’;

pPFrame.onreadystatechange= function()

{

if(pPWindow.document.readyState == ‘complete’)

{

pPWindow.document.body.style.backgroundColor = ‘#eef0f6’;

pPWindow.document.getElementsByTagName(‘TABLE’)[0].style.borderLeftWidth = ‘0px’;

}

}

}

else

{

document.all.IFRAME_ProductPurchase.src=”/aspx/IFrameMassage.htm”;

}

/*********** IFrame Code Ends Here **********************/

How to bind CRM Data to GridView on custom ASP.Net page for Microsoft Dynamics CRM

string fetch = @"   <fetch mapping=""logical"">
<entity name=""account"">
<attribute name=""accountid""/>
<attribute name=""name""/>
<attribute name=""address1_line1""/>
<attribute name=""address1_line2""/>
<attribute name=""address1_country""/>
<attribute name=""address1_city""/>
</entity>
</fetch>";

string result = service.Fetch(fetch);

XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
doc.DocumentElement.Attributes.RemoveAll();

StringReader sr = new StringReader(doc.OuterXml);
DataSet ds = new DataSet();
ds.ReadXml(sr);

GridView1.DataSource = ds;
GridView1.DataBind();
For More details see below link..

Data Audit In CRM

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Crm.Sdk;

using Microsoft.Crm.SdkTypeProxy;

using System.Collections.Specialized;

using System.Web.Services.Protocols;

using Microsoft.Crm.Sdk.Metadata;

using Microsoft.Crm.SdkTypeProxy.Metadata;

namespace CRM.Customization.DataAudit

{

public class DataAudit:IPlugin

{

private string primaryEntity = “”;

DynamicEntity preImageEntity = null;

DynamicEntity postImageEntity = null;

//string organizationName = null;

//  string logPath = null;

string serverNameWithPort = “10.10.41.5:5555”;

Guid recordGuid;

string auditTopic =“Opportunity”;

string relationshipSchemaName = “mul_opportunityauditid”;

#region IPlugin Members

public void Execute(IPluginExecutionContext context)

{

ICrmService service = context.CreateCrmService(true);

IMetadataService mservice = context.CreateMetadataService(true);

string label = string.Empty;

if (context.MessageName == “Update” || context.MessageName == “Assign”)

{

primaryEntity = context.PrimaryEntityName;

preImageEntity = (DynamicEntity)context.PreEntityImages.Properties[“PostImage”];

postImageEntity = (DynamicEntity)context.PostEntityImages.Properties[“PostImage”];

// Retrieve  id of entity

Key rGuid = (Key)postImageEntity.Properties[context.PrimaryEntityName + “id”];

recordGuid = rGuid.Value;

// Adding pre and post value of attribute to collection.

NameValueCollection prop = new NameValueCollection();

AddPropertiesToCollection(prop, preImageEntity, context.PrimaryEntityName, false);

AddPropertiesToCollection(prop, postImageEntity, context.PrimaryEntityName, true);

foreach (string key in prop)

{

// using visual  basic split method in order to split on a string, instead of a character

string[] arr = Microsoft.VisualBasic.Strings.Split(prop[key], “|,|”, -1, Microsoft.VisualBasic.CompareMethod.Text);

if (arr.Length > 1)

{

if (arr[0] != arr[1])

{

// calling getLabel method to retrieve the label of Field

label = GetLabel(mservice,key, context.PrimaryEntityName, context.OrganizationName, serverNameWithPort);

//if the value do not match, then insert a record into our DataAudit table

InsertAuditRecord(service, context.PrimaryEntityName, auditTopic, label, arr[0], arr[1]);

}

}

else

{

//if the array length is 1, then we have a case where a text value was changed

//to or from blank value.

// need to split on just the resulting string

string[] arrBlankText = prop[key].Split(‘|’);

if (arrBlankText.Length > 1)

{

// calling getLabel method to retrieve the label of Field

label = GetLabel(mservice,key, context.PrimaryEntityName, context.OrganizationName, serverNameWithPort);

//if the value do not match, then insert a record into our DataAudit table

InsertAuditRecord(service, context.PrimaryEntityName, auditTopic, label, arrBlankText[0], arrBlankText[1]);

}

}

}

}

}

private void InsertAuditRecord(ICrmService service, string entityName, string topic, string AttributeName, string PreviousValue, string NewValue)

{

try

{

// Create instance of Dynamic Entity

DynamicEntity dynamicEntity = new DynamicEntity();

dynamicEntity.Name = “new_dataaudit”;

// Instantiate a string property.

StringProperty attribute = new StringProperty();

attribute.Name = “new_attribute”;

attribute.Value = AttributeName;

StringProperty oldValue = new StringProperty();

oldValue.Name = “new_previousvalue”;

oldValue.Value = PreviousValue;

StringProperty newValue = new StringProperty();

newValue.Name = “new_newvalue”;

newValue.Value = NewValue;

StringProperty entity = new StringProperty();

entity.Name = “new_name”;

if (entityName.StartsWith(“new_”))

{

entity.Value = entityName.Substring(4);

}

else

{

entity.Value = entityName;

}

// Set topic for audit record

//CrmSdk.StringProperty recordTopic = new CrmSdk.StringProperty();

//recordTopic.Name = auditTopic;

//recordTopic.Value = topic;

LookupProperty entityLookup = new LookupProperty();

entityLookup.Name = relationshipSchemaName;

entityLookup.Value = new Lookup();

entityLookup.Value.Value = recordGuid;

entityLookup.Value.type = entityName;

// Set the properties for entity.

//dynamicEntity.Properties = new Property[] { entity, attribute, oldValue, newValue, entityLookup };

dynamicEntity.Properties.Add(entity);

dynamicEntity.Properties.Add(attribute);

dynamicEntity.Properties.Add(oldValue);

dynamicEntity.Properties.Add(newValue);

dynamicEntity.Properties.Add(entityLookup);

TargetCreateDynamic myTarget = new TargetCreateDynamic();

myTarget.Entity = dynamicEntity;

CreateRequest create = new CreateRequest();

create.Target = myTarget;

CreateResponse myResponse = (CreateResponse)service.Execute(create);

}

catch (SoapException ex)

{

throw ex;

}

catch (Exception ex)

{

throw ex;

}

}

public void AddPropertiesToCollection(NameValueCollection prop, Microsoft.Crm.Sdk.DynamicEntity entityData, string entityName, bool postData)

{

string attributeName;

string attributeValue;

string attributeModValue;

PropertyCollection dyProperty = entityData.Properties;

//Loop through the field

foreach (Microsoft.Crm.Sdk.Property property in dyProperty)

{

attributeValue = string.Empty;

attributeModValue = string.Empty;

// Get the attributes name

attributeName = property.Name;

//WriteLog(entityName, “Update”, attributeName, “—–“);

// attributeValue = GetValueFromProperty(entityTypeCode, currentProperty, postData);

attributeValue = GetValueFromProperty(entityData, entityName, attributeName, property);

//Add a pipe character after the value if we are looping through the pre data

//or before the value if we are looping through the post data.

attributeModValue = (postData) ? “|” + attributeValue : attributeValue + “|”;

//skip these values , since they changes on every update

if ((attributeName != “modifiedon”) && (attributeName != “modifiedby”))

{

prop.Add(attributeName, attributeModValue);

}

}

}

public string GetValueFromProperty(Microsoft.Crm.Sdk.DynamicEntity prePostImageEntity, string entityName, string attributeName, Microsoft.Crm.Sdk.Property inputProperty)

{

Type propType = inputProperty.GetType();

string propValue = string.Empty;

// string propValue1 = string.Empty;

if (propType == typeof(Microsoft.Crm.Sdk.StringProperty))  // if field is of type string.

{

propValue = ((Microsoft.Crm.Sdk.StringProperty)inputProperty).Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CustomerProperty))  // if field is of Customer type.

{

propValue = ((Microsoft.Crm.Sdk.CustomerProperty)inputProperty).Value.name.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmBooleanProperty)) // if field is of CrmBoolean type.

{

propValue = ((Microsoft.Crm.Sdk.CrmBooleanProperty)inputProperty).Value.Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmMoneyProperty))        // if field is of CrmMoney type.

{

propValue = ((Microsoft.Crm.Sdk.CrmMoneyProperty)inputProperty).Value.Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmDateTimeProperty))     // if field is of CrmDateTime type.

{

string myValue;

myValue = ((Microsoft.Crm.Sdk.CrmDateTimeProperty)inputProperty).Value.Value.ToString();

propValue = Convert.ToDateTime(myValue).GetDateTimeFormats()[3];

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmDecimalProperty))      // if field is of CrmDecimal type.

{

propValue = ((Microsoft.Crm.Sdk.CrmDecimalProperty)inputProperty).Value.Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmFloatProperty))  // if field is of CrmFloat Type.

{

propValue = ((Microsoft.Crm.Sdk.CrmFloatProperty)inputProperty).Value.Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.CrmNumberProperty))       //if field is of CrmNumber Type.

{

propValue = ((Microsoft.Crm.Sdk.CrmNumberProperty)inputProperty).Value.Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.LookupProperty))          //if field is of Lookup Type.

{

if (inputProperty.Name.ToString() != “owningbusinessunit”)

propValue = ((Microsoft.Crm.Sdk.LookupProperty)inputProperty).Value.name.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.OwnerProperty))       //if field is of owner type.

{

propValue = ((Microsoft.Crm.Sdk.OwnerProperty)inputProperty).Value.name.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.StatusProperty))  // if field is of type Status

{

propValue = ((Microsoft.Crm.Sdk.StatusProperty)inputProperty).Value.ToString();

}

else if (propType == typeof(Microsoft.Crm.Sdk.PicklistProperty))  //if field is of type Picklist

{

propValue = ((Microsoft.Crm.Sdk.PicklistProperty)inputProperty).Value.name.ToString();

}

return propValue;

}

public string GetLabel(IMetadataService service, string fieldName, string entityName, string organizaionName, string serverName)

{

string display = string.Empty;

//call instance of MetaDataService to call a web service

RetrieveAttributeRequest request = new RetrieveAttributeRequest();

request.EntityLogicalName = entityName;

request.LogicalName = fieldName;

RetrieveAttributeResponse response = (RetrieveAttributeResponse)service.Execute(request);

// Get Type of Field

Type attributeType = response.AttributeMetadata.GetType();

// Access the retrieved attribute

if (attributeType == typeof(DecimalAttributeMetadata))

{

DecimalAttributeMetadata retrievedAttributeMetadata = (DecimalAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(FloatAttributeMetadata))

{

FloatAttributeMetadata retrievedAttributeMetadata = (FloatAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(IntegerAttributeMetadata))

{

IntegerAttributeMetadata retrievedAttributeMetadata = (IntegerAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(MoneyAttributeMetadata))

{

MoneyAttributeMetadata retrievedAttributeMetadata = (MoneyAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(LookupAttributeMetadata))

{

LookupAttributeMetadata retrievedAttributeMetadata = (LookupAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(PicklistAttributeMetadata))

{

PicklistAttributeMetadata retrievedAttributeMetadata = (PicklistAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(StateAttributeMetadata))

{

StateAttributeMetadata retrievedAttributeMetadata = (StateAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(StatusAttributeMetadata))

{

StatusAttributeMetadata retrievedAttributeMetadata = (StatusAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(StringAttributeMetadata))

{

StringAttributeMetadata retrievedAttributeMetadata = (StringAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

else if (attributeType == typeof(DateTimeAttributeMetadata))

{

DateTimeAttributeMetadata retrievedAttributeMetadata = (DateTimeAttributeMetadata)response.AttributeMetadata;

LocLabel localLabel = retrievedAttributeMetadata.DisplayName.UserLocLabel;

display = localLabel.Label;

}

return display;

}

#endregion

}

}

One thought on “Dynamics 365”

Leave a Reply to Garland Leverton Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s