Operation failed due to a SQL integrity violation


Hi,

Today i was suppose to write a callout which would be sending email to owner’s manager for our opportunity entity.

I thought before trying out with an callout(which is really hard to debug) i should try it first in a windows application. Finally after some time i was able to get it working.

So than i decided to put the same code in the callout as well. But to my surprise i found that the same code was not working in the callout.

This was the error i was getting as

ex.detail.innerxml // for (SoapException ex)

<error>
<code>0x80040237</code>
<description>Operation failed due to a SQL integrity violation.</description>
<type>Platform</type>
</error>

After searching on the internet for the same i was able to find the cause for the error in my code

For my windows application this piece of code was sufficient

CrmService service=new CrmService();
service.Credentials=System.Net.CredentialCache.DefaultCredentials;
service.Url=”http://d-2927:5555/mscrmservices/2006/crmservice.asmx&#8221;;

But when it came to callout it had to be

CrmService service=new CrmService();
service.Credentials=System.Net.CredentialCache.DefaultCredentials;
service.Url=”http://d-2927:5555/mscrmservices/2006/crmservice.asmx&#8221;;
service.CallerIdValue = new CallerId();
service.CallerIdValue.CallerGuid =userContext.UserId;

This helped me to solve the error.

Check this link as well

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1768766&SiteID=1

Bye

Using Dhtml inside CRM


Hi,

We can make use of Dhtml inside our CRM onLoad, onSave and onChange javascripts.

Using Dhtml, number of possible ways of customizing CRM increases.

But the only thing with them is that they are unsupported.

Just for fun try putting this code in form load of your contact form and see what it does.

window.status=”Hello CrmUser!”;
window.resizeTo(600,600);
function G_GlowField()
{
event.srcElement.runtimeStyle.backgroundColor=”Yellow”;
var p=window.createPopup()
var pbody=p.document.body
pbody.style.backgroundColor=”lime”
pbody.style.border=”solid black 1px”
pbody.innerHTML=”Mandatory Field”
p.show(150,150,200,50,document.body)

}
function G_RevertField()
{
event.srcElement.runtimeStyle.backgroundColor=””;
}
crmForm.all.firstname.attachEvent(“onmouseover”,G_GlowField);
crmForm.all.firstname.attachEvent(“onmouseout”,G_RevertField);
crmForm.all.firstname.attachEvent(“onmousedown”,G_RevertField);

Or Better check this link

Using the attachEvent method to show users context sensitive help

Bye

Link Entity, Query Expression and FetchXml Wizard


Let say we need to make use of CrmService to give us the name of the opportunity where owner’s fullname=’someName’;

Name is an attribute of Opportunity Entity.
FullName is an attribute of SystemUser Entity.

So we need to make use of LinkEntity class over here to link from opportunity entity to systemuser entity.

Now let’s use queryExpression for the same.

 

But plzzzz don’t write it yourself, use FetchXmlBuilder to write it for you.
Plzz understand it and download it from this link

http://www.stunnware.com/crm2/topic.aspx?id=FindingData6
(The best site for all the CrmDevelopers)

This is how the queryExpression code will look like

 

QueryExpression query = new QueryExpression();

query.EntityName = “opportunity”;

ColumnSet columns = new ColumnSet();
columns.Attributes = new string[] { “name” };
query.ColumnSet = columns;

LinkEntity linkEntity1 = new LinkEntity();
linkEntity1.JoinOperator = JoinOperator.Natural;
linkEntity1.LinkFromEntityName = “opportunity”;
linkEntity1.LinkFromAttributeName = “owninguser”;
linkEntity1.LinkToEntityName = “systemuser”;
linkEntity1.LinkToAttributeName = “systemuserid”;

linkEntity1.LinkCriteria = new FilterExpression();
linkEntity1.LinkCriteria.FilterOperator = LogicalOperator.And;

ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = “fullname”;
condition1.Operator = ConditionOperator.Equal;
condition1.Values = new object[] { “Nishant Rana” };

linkEntity1.LinkCriteria.Conditions = new ConditionExpression[] { condition1 };

query.LinkEntities = new LinkEntity[] { linkEntity1 };

Now say we have a requirement where we need

The name of all the opportunity along with the fullname of the owner.

Let’s try doing it with a queryExpression class and using the FetchXmlBuilder.

This is the code which we’ll get

………….

LinkEntity linkEntity1 = new LinkEntity();

linkEntity1.JoinOperator = JoinOperator.Natural;

linkEntity1.LinkFromEntityName = “opportunity”;

linkEntity1.LinkFromAttributeName = “owninguser”;

linkEntity1.LinkToEntityName = “systemuser”;

linkEntity1.LinkToAttributeName = “systemuserid”;

//You have specified columns for this link-entity. This is not supported in query expressions

 

This means it’s not possible using queryExpression

So in this case we need to make use of FetchXml to fetch use the fullname of the owning user.

The fetch xml looks like this

string fetchXml = @”
<fetch mapping=””logical”” count=””50″”>
<entity name=””opportunity””>
<attribute name=””name”” />
<link-entity name=””systemuser”” from=””systemuserid”” to=””owninguser””>
<attribute name=””fullname”” />
</link-entity>
</entity>
</fetch>”;

// Finally the code

CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
string fetchXml = @”
<fetch mapping=””logical”” count=””50″”>
<entity name=””opportunity””>
<attribute name=””name”” />
<link-entity name=””systemuser”” from=””systemuserid”” to=””owninguser””>
<attribute name=””fullname”” />
</link-entity>
</entity>
</fetch>”;
String result = service.Fetch(fetchXml);

 

Now the only problem is we need to parse the xml on our own.

We can use something like this

if this is the result we are receiving

<resultset morerecords=”0″><result><new_id>GP0677</new_id></result></resultset>

to fetch the new_id we can do this

XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
XmlNodeList xnodlist=doc.GetElementsByTagName(“
new_id”);
XmlNode xnodRoot=xnodlist.Item(0);
string val=xnodRoot.InnerText;

 

 

Bye.

 

Using ALLColumns() in Dynamics CRM


Hi,

To retireve the values for all the attributes of an entity we can make use of ALLColumns ,

CrmService service=new CrmService();

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

QueryExpression query = new QueryExpression();

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

query.ColumnSet=new AllColumns();

BusinessEntityCollection entities= service.RetrieveMultiple(query);

for(int i=0;i<entities.BusinessEntities.Length;i++)

{

new_entityname nEntity=(new_entityname) entities.BusinessEntities[i];

Response.Write(“<b>”+nEntity.new_id+” -></b>”);

Response.Write(“<i>” + nEntity.createdby.name + ” –></i>”);

}

}

Or by using QueryByAttribute  

It can be used when our query is very simple i.e. multiple equals conditions that are combined using AND.

But remember it doesn’t support OR
QueryByAttribute myQuery=new QueryByAttribute();
myQuery.ColumnSet=new AllColumns();
myQuery.EntityName=EntityName.opportunity.ToString();

    // Find all the opportunities with topic name test1 and city as Redmond
myQuery.Attributes=new string[]{“name”,”address1_city”};
myQuery.Values=new string[]{“Test1″,”Redmond”};
BusinessEntityCollection retrieved=service.RetrieveMultiple(myQuery);

Bye

Query for finding Team and it’s member in MS DYNAMICS CRM


Hi,

We can use this query to retrieve different teams and the users belonging to that team within Microsoft Dyanmics CRM

Select FT.name TeamName,FSU.Fullname UserName, FSU.Systemuserid from
dbo.FilteredSystemUser FSU
inner Join
dbo.FilteredTeamMembership FTM  
on FSU.Systemuserid = FTM.Systemuserid
Inner join  dbo.FilteredTeam FT
on FT.TeamID = FTM.TeamID
ORDER BY FT.NAME

Bye

Hiding or disabling elements in Microsoft Dynamics CRM 3.0


Aim : To disable the close opportunity menu item from the Actions Menu for Opportunity form.

Put the following code in the Form_Load script of the Opportunity form

document.getElementById(‘_MIcomplete’).Style=”display:none” ;


Put the id of the menu item there
To get the id name for any particular menu item

  • step 1- open the opportunity form in crm.

  • step 2- press ctrl+N to open the same form in a new window.

  • step 3- right click go to view source and find the id of the required element.

Same thing we can do for buttons added through isv.config as well as other elements

ISV_New_1_199_Billing.style.display = “none” ;

Bye