Post data to CRM 2013 from Infopath using XRM

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

Step 1

Create an InfoPath Form

Pic10

Step2:

Go to File menu à Submit Options. In that select the option as shown in the Pic below

Pic11

 

Step 3:

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);

_serviceProxy.Create(Contact);

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

 

Step 4:

Give Full trust permission to the form. Go to file menu à Form Options.

Follow as per below diagram

Pic12

Save the form and preview the form. And submit it, you can see the record is created in the CRM.

Happy Coding

 

Elam

CRM 2013 Sub-grid user experience for new record creation

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:

pic1

CRM reveals a lookup control to allow the user to browse for an existing record:

pic2

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:

pic3

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:

pic4

Saving that new record automatically closes the form and refreshes the parent form revealing new child record in the sub-grid:

pic5

 

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:

pic6

Ribbon Workbench is showing me 2 buttons, I am going to hide both. Then I publish the change:

pic7

Now the Behavior changed.

Here’s the user experience now…

The user clicks the + button:

pic8

And up pops up for create form:

pic9

It’s a supported way, we are just changing only the Ribbon button

Elam

Entity Images in CRM 2013

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:\path\to\image\file.jpg”);

sdk.Update(account);

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

Regards,

Elam

 

Microsoft E-book Gallery

http://social.technet.microsoft.com/wiki/contents/articles/11608.e-book-gallery-for-microsoft-technologies.aspx

Posted from WordPress for Windows Phone

Posted from WordPress for Windows Phone

Category: General  Tags:  Leave a Comment

First post from my mobile

Today was a great day. I had moved my blog to godaddy hosting and installed new theme. Planning to start my blog journey again.this time I plan to write on technical and also what is happening around me. Need to write at least two post in a week.
Let’s hope for the best
Have a great week

Category: General  Leave a Comment

Shrink LDF file in SQL SERVER 2008

Reposting it again :)

 

Today i had a problem.  when i checked my database LDF file (log) file it’s some where around 25GB. I was trying to shrink the file it’s not possible. Could not able to shrink it from management studio. Found an workaround for that, Here the command for it.

First make the database to SIMPLE Recovery mode and do it.

– Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE [databasename]
SET RECOVERY SIMPLE;
GO
– Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE ([log file name], 1);
GO
– Reset the database
ALTER DATABASE [databasename]
SET RECOVERY FULL;
GO

Let me know if any questions

Elam

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Improve the single page visitor

Yesterday when i was looking at my website data i found most of the my visitor are single page visitor. Who came down to my 2 post one is for SQL server and another to Jquery page. Both the posts ranked well in the google. Now my problem is how to convert this visitor to see other posts ? .

Here is what i am planning to convert the visitor

1) Given the link to other corresponding pages in that post
2) Written couple of continues post for that topics

These will increase the visitor. will update the post again in another one month

Regards,
Elam

Shrink LDF file in SQL SERVER 2008

Today i had a problem.  when i checked my database LDF file (log) file it’s some where around 25GB. I was trying to shrink the file it’s not possible. Could not able to shrink it from management studio. Found an workaround for that, Here the command for it.

First make the database to SIMPLE Recovery mode and do it.
 
– Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE [databasename]
SET RECOVERY SIMPLE;
GO
– Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE ([log file name], 1);
GO
– Reset the database
ALTER DATABASE [databasename]
SET RECOVERY FULL;
GO

Let me know if any questions

Elam

Category: Technical  Tags:  Leave a Comment

Steps to check website and Sql performance

Hi all,
It’s been very long time since i updated my blog.  i am really sorry for that. Well coming to the topic. I was working for one of our entrprise customer. We have web analytics data close to 90GB.  we are building another application to displaying the data, so i need to migrate the data to new database.

Intially when we started our migration it takes almost 6 days for one month data. I was wondering what to da. Then i followed the below mention steps and it come down to 3 Hours for one month.

Steps
1 check for each query execution time and also the subtree cost.  to get subtree cost include execution steps from the top bar in management studio. When sub tree cost is more sql server uses full 100% cpu time and memory.
2 created the index for each table.  while creating index make sure you create index for all where condition combination.
3 use temp table instead of union all query. Because i combine almost 60 table in single query. So instead of union all i used temp table to get the data
4 remove unnessary column in the select statement

Once you follow this points. It  will increase the website and sql performance

If any questions just mail me or add a comment

Elam