TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Using Upsert in Microsoft Dynamics CRM 2015 Update 1
Mahender Pal
Jul 01, 2015
8.8
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
This blog is about new feature in Microsoft Dynamics CRM 2015 Update .
Another useful feature that is introduced in Dynamics CRM 2015 update 1 is support for upsert operation. Upsert allows us to create or update record in CRM in single call, so we don't need to bother if there is any existing record with the same keys or combination of other fields. This is specially useful in case of integration, when we are not sure that record from other system is already integrated with CRM or not. We can use upsert with alternate keys, Please refer our
earlier blog
for how to use alternate keys. Let's take below example where we are writing a account request, using upsertrequest:
Entity account =
new
Entity(
"account"
,
"accountnumber"
,
"UPST601"
);
account[
"name"
] =
"Upsert Demo"
;
account[
"revenue"
] =
new
Money(5000);
UpsertRequest request =
new
UpsertRequest()
{
Target = account
};
UpsertResponse response = (UpsertResponse) service.Execute(request);
if
(response.RecordCreated) Console.WriteLine(account[
"name"
] +
" Created with Revenue: "
+ account.GetAttributeValue < Money > (
"revenue"
).Value);
else
Console.WriteLine(account[
"name"
] +
" Updated with Revenue: "
+ account.GetAttributeValue < Money > (
"revenue"
).Value);
Console.WriteLine(
"-----------------------------------"
);
account[
"revenue"
] =
new
Money(15000);
UpsertRequest request1 =
new
UpsertRequest()
{
Target = account
};
response = (UpsertResponse) service.Execute(request);
if
(response.RecordCreated) Console.WriteLine(account[
"name"
] +
" Created with Revenue: "
+ account.GetAttributeValue < Money > (
"revenue"
).Value);
else
Console.WriteLine(account[
"name"
] +
" Updated with Revenue: "
+ account.GetAttributeValue < Money > (
"revenue"
).Value);
Console.ReadLine();
As you can see in above code we are executing upsert request two times, so first time as this record is not available in CRM, it will create it, but while executing next statement it will update existing record instead of creating it.
HIMBAP
| Need any help in Microsoft CRM 2015 Development
Contact US !!
Microsoft Dynamics CRM
Upsert in Microsoft Dynamics CRM
Next Recommended Reading
Generate PDF File Using JavaScript in Microsoft Dynamics CRM 2015
HIMBAP
We are expert in Microsoft Power Platform.