Update Custom Entities in MS CRM 4.0 via Custom Workflow - dynamics-crm

I have created a custom entity in MS CRM 4.0 and am trying to update a couple of the attributes via a custom worflow in .Net. I have read through several of the forums and blog posts and am still confused on how to access the custom entity and update some of their attributes.
I created a custom entity to replace how CRM was doing allotments as our company has some specific business rules that CRM wasn't doing. When a task is completed on an incident I want to update an attribute in the custom entity with the task duration. Any help would be greatly appreciated.
Thanks

When using the CRM web service in a custom workflow, you'll need to use DynamicEntity objects. The workflow context webservice is just an ICrmService so it doesn't know about your specific customizations. There's a pretty sample here: http://www.stunnware.com/crm2/topic.aspx?id=CustomWorkflowActivity
I imagine you could also add the CRM web services as a web reference to your workflow project. Then you'd have strongly types objects for your custom entities. I've never done this for my custom workflows, but it works for other custom apps accessing CRM.

Choosing Dynamic Entities over WSDL in favour is always the better choice.
When you develop a piece of code, you are more flexible with your classes. You could use your piece of software in different contexts for different systems. That's the reason Dynamic Entities were invented.

It's very easy and you dont'have to use DynamicEntity. You have to go to Settings -> Customization -> Download WSDL. Take the wsdl and use it in your project. Now you have all your custom entities strongly typed. All you have to do is to write something like this:
Guid entityId = getEntityId();
new_yourCustomEntity entity = new new_yourCustomEntity();
entity.new_yourCustomEntityid = entityId;
entity.new_customProperty = "value";
CrmService crmService = new CrmService();
crmService.Update(entity);

Maybe what you really mean is Custom Workflow Activity? This involves writing your own .NET class to add functionality to the standard CRM WF in form of new step types. If what you want to do is just to update an attribute you don't really need this, even if it is on a custom entity. The Update record step does just this and allows dynamic values (coming from other entities) to be specified.
Hope it helps
Daniel

Related

Tool for creating object representations for Entities in Dynamics

Similar to Entity Framework I would like to know if there is a tool or nuget package I can use where I can just send the Dynamics URL and credentials in order to create object models from a Dynamics System. I'm trying to avoid creating custom DTOs.
You can use CrmSvcUtil to generate strongly-typed classes for entities.
Command line:
CrmSvcUtil.exe /url:http://<serverName>/<organizationName>/XRMServices/2011/Organization.svc /out:<outputFilename>.cs /username:<username> /password:<password> /domain:<domainName> /namespace:<outputNamespace> /serviceContextName:<serviceContextName>
GUI: (by Daryl from community)
Early Bound Generator in XrmToolbox & its video tutorial + documentation
Early Bound Generator included in the XrmToolbox is the simplest. https://www.xrmtoolbox.com/
Find the right configuration then take the command line and include it in a batch file under source control. You'll have to run it each time you add fields in CRM, depending on your needs. If you lose your starting configuration, your code might not be compatible the next time you generate.

Click-To-Call feature for Dynamics CRM (like Lync/Skype)

Advance warning: Im an absolute newbie to Dynamics CRM!
Intention
I want to have a feature like Lync/Skype integration but use my own URL. (Click on any telephone number inside CRM and call it).
For eg. assuming I have a web service which can initiate a call per URL: http://telephony.com/call?nr=012345678. Now, whenever a CRM user clicks onto a telephone number field (in forms and views) inside the CRM my web service should be called instead of Skype/Lync.
In fact I'm trying to reproduce sth. like the InGenius Connecter.
Attempts
I already tried to inject a JS web resource to a specific formular (in my case it was the default contact form) and override the Mscrm.ReadFormUtilities.openPhoneClient callback (which seems to handle the Lync/Skype integration).
function load() {
// override integrated CTC (Lync/Skype)
Mscrm.ReadFormUtilities.openPhoneClient = function (telephoneNr) {
// redirect user to my web service
window.location.replace("http://telephony.com/call?nr="+telephoneNr);
return;
}
}
Found this method at: Disable Lync completely
This does work well in forms of Dynamics 2015 (my custom link pops up instead of Skype/Lync). However, this does only work on entity forms since I can't inject web resources into an entity view.
My other ideas how to implement such a feature are:
Inject global JS resource which disables Lync/Skype and encapsulate every telephone number with link to my custom URL.
Extend/Manipulate Lync/Skype integration to use my custom URL instead of Lync/Skype.
Write plugin which encapsulate telephone numbers server side.
Question
Since I have a grasp understanding of Dynamics and no experience in plugin/resource development, I'm left a bit confused with these questions.
Is it possible to achieve any of the three ideas above ?
If not, any idea how InGenius solved this problem ?
Do you have any other idea/resources about this topic ?
Currently I found two options available to achieve a custom CTC feature. (Both has the downside of not being officialy supported by the dynamics crm.)
Global Ribbon
Pretty simple: Add a Click-To-Call button to global ribbon which is only enabled on specific grids when one row is selected.
This button refers to an JS-Action which retrieves the telephone number via ODATA and then launches the dial process.
Global Ribbon CustomRule injection
Add a global button to ribbon which refers to a JS resource per <CustomRule>. The JScript then unbinds all actions from links with .ms-crm-Phone classes and replaces its href-attribute.
This would be useful if one want to override the integrated "Skype / Lync - Click to Dial" feature with his own logic.
I didn't test this method until now, so I can't guarentee it's working !
Note: I will include example scripts as soon I got the time.

How to force adding and removing of objects from the entity framework through the service layer?

I am struggling with solving how to handle insertions and deletions with MVC3 and the Entity Framework 4.2
My Setup:
Website accesses my Service Layer, which uses the Repository Pattern to fetch and return my Model(POCO) objects. The Solution is separated into the following projects:
DAL(Data)
BAL(Service layer in here)
MODELS (Poco objects)
WEBSITE (presentation)
My Problem:
I need to be able to control the adding and deletion of objects and run whatever business logic I like. This should be done in the Service Layer.
Example of Problem: I have an Account class with an ICollection of AccountContact objects. Each AccountContact object has an ICollection of PhoneNumber objects. What I envision is a Service method something like this
AddAcountContact(Account account, AccountContact accountContact){
//Run business logic to ensure that this account contact can be added
account.AccountContacts.Add(accountContact);
unitOfWork.SaveChanges();
}
DeleteAccountContact(Account account, AccountContact accountContact){
//Run business logic to ensure that this account contact can be deleted
account.AccountContacts.Remove(accountContact);
unitOfWork.SaveChanges();
}
Unfortunately I have no way to force adding and removing through my Service class. A developer could easily insert/remove directly from the presentation layer. Anyone have any ideas or know common solutions to this problem? Perhaps I am doing something wrong....
If you expose class with public collection property allowing Add and Remove you are telling developers that they can call those methods. You can define the coding policy and use code review to check that policy is followed but it is only workaround. Still anybody could forget about that and call Add or Remove directly because your classes are wrongly designed.
The main problem here are entities exposed directly to UI. If you don't want direct modification of entities in UI layer simply don't expose them to that layer. Use another type (DTO / View model) with readonly collections exchanged between service layer and UI layer and convert that type to entity inside service layer. Another option is adding validation directly to entities or custom collection types.

MVC3 is valid email

Is there a built in function which will test if an email address is valid?
I want to test the email address structure is valid before sending a confirmation email to the end user.
I understand i could create my own function easy enough with the use of a regular expression but if there is a built in function i would much rather use this.
You can do this with Data Annotations extensions I believe. Check out Scott Guthrie's blog post on it here: http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx.
There is a good point in Scott's post as to why you would use this rather than the MVC 3 Futures validators which might be relevant to your choice:
ASP.NET MVC 3 futures defines four new data annotations attributes which this project has as well: CreditCard, Email, Url and EqualTo. Unfortunately referencing MVC 3 futures necessitates taking an dependency on MVC 3 in your model layer, which may be unadvisable in a multi-tiered project. Data Annotations Extensions keeps the server and client side libraries separate so using the project’s validation attributes don’t require you to take any additional dependencies in your model layer which still allowing for the rich client validation experience if you are using MVC 3.
Yes, you can use
public class CustomerMetaData
{
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress;
}
on your model. See more about it here.
however, last time I checked it does not work client sided.
I googled it, and from imran baloch's blog post it seems it does work now.

How to send Linq data class via WCF and bind input control with this class property?

For strongly-typed & type-safe solution, I have to do the following step.
Create some Silverlight application.
Binding input control to Linq data class.
Validate data by using rule from attribute of data class.
Send data to server via WCF.
But, I have some question.
How to bind input control with linq data class property?
How to do that with minimal tiers(layers) and minimal required dll(for Silverlight project)?
PS. .Net RIA Service - May Preview isn't my final answer. Because size of all required dll and some generated code.
Thanks,
Well, I'm glad you know that .NET RIA Services will provide all of those things but I understand size is a consideration. Keep in mind though, since it looks like you're considering Silverlight 3 you can use the option to cache the framework assemblies to greatly reduce your Xap size:
http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/06/silverlight-3-s-new-assembly-caching.aspx
I'm not positive that caching applies to the RIA Services assemblies, but if so it would mean they're downloaded only once.
Assuming that's not what you want there are 2 other options to get data from the Linq classes (I'll assume you mean Entity Framework classes) to the client. The most simple method would be to create your own WCF Service as you've mentioned. That way you write data classes on the server and proxy classes automatically get generated on the client that mimic the server classes. The drawback here is business rules won't be shared between the two. So your data validation attributes will need to be written and enforced on the client & the server separately.
The next option is to use ADO.NET Data Services to move the data from the server to the client. This is a step above the previous option in that you won't have to write a WCF service yourself to host the data; it's generated for you. Of course it requires an extra Dll to be packaged in the Xap.
To answer some of your questions directly:
You can't ever bind an input control directly to a Linq data class. You can only bind controls to the client side proxy classes that are generated by referencing a WCF service (either one you wrote yourself or one provided by ADO.NET Data Services).
If you don't use .NET RIA Services you'll need to create a custom attribute to link to your business rules, then handle events on the data bindings manually to read the attribute and enforce your rules.
Use either of the above options to send data to the server - either your own custom WCF Service or ADO.NET Data Services.
Your final question about binding an input control to a property looks like this:
MyControl.xaml.cs:
public MyControl() {
this.DataContext = new LinqDataClass();
}
MyControl.xaml:
<TextBlock Text={Binding PropertyOnLinqDataClass}/>
Here, LinqDataClass is the client side representation of your server side Linq data class and has a property called PropertyOnLinqDataClass. You'll need to implement the INotifyPropertyChanged interface on the client side to properly support 2 way data binding.

Resources