Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Using Upsert in Microsoft Dynamics CRM 2015 Update 1
WhatsApp
Mahender Pal
9y
8.8
k
0
1
25
Blog
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
Up Next
Generate PDF File Using JavaScript in Microsoft Dynamics CRM 2015
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
HIMBAP
We are expert in Microsoft Power Platform.
Membership not found