There was ask form me to check, whether we can post data to CRM 2013 Via InfoPath 2013 form. I was aware that we can call a Custom WCF service which call CRM service and post the data to CRM from InfoPath form.
I was wondering whether we can use the custom code in the InfoPath to post the data to CRM. I did a small POC and found that it’s possible to post data using XRM sdk from InfoPath form
Here are the steps to follow
Create an InfoPath Form
Go to File menu à Submit Options. In that select the option as shown in the Pic below
Click on the Edit code and VS Will open and add the below code in the FormEvents_Submit
var Contact = new Entity("Contact");
Contact.Attributes["name"] = "Test from crm";
Uri oUri= new Uri("https://<Orgname>.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");
//** Your client credentials
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = <<username>;
clientCredentials.UserName.Password = <<Password>>;
//Create your Organization Service Proxy
OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(oUri,null,clientCredentials,null);
And also refer the below XRm Dll’s
using Microsoft.Xrm.Sdk; (Microsoft.Xrm.Sdk.dll)
using Microsoft.Xrm.Sdk.Client; (Microsoft.Xrm.Sdk.dll)
using System.ServiceModel.Description; (System.ServiceModel.dll)
Build the code and close the VS
Give Full trust permission to the form. Go to file menu à Form Options.
Follow as per below diagram
Save the form and preview the form. And submit it, you can see the record is created in the CRM.
We have an odd design choice in CRM 2013 with the new sub-grid design. By default, when you add a new 1: N sub-grid to a form to display a custom entity you will get the following user experience. The user clicks the + icon to add a new child record via the sub-grid:
CRM reveals a lookup control to allow the user to browse for an existing record:
If user want to add a new record, the user clicks the + button and the lookup appears. They don’t want to search for a record but the only thing they can do to move forward is click on the magnifying glass, this executes a search and reveals the lookup control’s search results:
There is however a new “+ New’ button for user, so user need to press that. That gets where user want to be, popping the create form so user can create my new child record:
Saving that new record automatically closes the form and refreshes the parent form revealing new child record in the sub-grid:
I want to change the default behavior. Now I used Ribbon Workbench and call up the Ribbon definition for my entity. I right-click on the “Add Existing” and select Hide Button:
Ribbon Workbench is showing me 2 buttons, I am going to hide both. Then I publish the change:
Now the Behavior changed.
Here’s the user experience now…
The user clicks the + button:
And up pops up for create form:
It’s a supported way, we are just changing only the Ribbon button
Another new feature is CRM 2013 is the ability to set a record specific image. This feature is useful for putting company logos on the account record, a person’s face on a contact record or an image for a product record or add a image to a user record.
To update the image through the CRM 2013 user interface, simply click on the image and then select a file (less than 5mB) then click upload
To update the image via the SDK; it is very similar to updating any other attribute/field in CRM. Simply specify the ID of the record you want to update and then set the “entityimage” field to the actual bytes of the file.
Entity account = new Entity(“account”);
account[“accountid”] = _testAccountId;
account[“entityimage“] = File.ReadAllBytes(“c:pathtoimagefile.jpg”);
Entity Image data is stored in a new table called ImageDescripter which you can see below.
we can have images for custom entity, which i will show in the next post