Parameters

Return Value

Example

The following example shows how to use the Create method to create an account record (early bound). For this sample to work correctly, you must be connected to the server to instantiate an IOrganizationService interface. You can find the complete sample in the sample code package in the folder SampleCode\CS\GeneralProgramming\EarlyBound\CRUDOperations.cs.

' Connect to the Organization service.
' The using statement assures that the service proxy will be properly disposed.
_serviceProxy = ServerConnection.GetOrganizationProxy(serverConfig)
Using _serviceProxy
' This statement is required to enable early-bound type support.
_serviceProxy.EnableProxyTypes()
CreateRequiredRecords()
' Instantiate an account object.
' See the Entity Metadata topic in the SDK documentation to determine
' which attributes must be set for each entity.
Dim account_Renamed As Account = New Account With {.Name = "Fourth Coffee"}
' Create an account record named Fourth Coffee.
_accountId = _serviceProxy.Create(account_Renamed)
Console.Write("{0} {1} created, ", account_Renamed.LogicalName, account_Renamed.Name)
' Retrieve the account containing several of its attributes.
Dim cols As New ColumnSet(New String() {"name", "address1_postalcode", "lastusedincampaign", "versionnumber"})
Dim retrievedAccount As Account = CType(_serviceProxy.Retrieve("account", _accountId, cols), Account)
Console.Write("retrieved ")
' Retrieve version number of the account. Shows BigInt attribute usage.
Dim versionNumber? As Long = retrievedAccount.VersionNumber
If versionNumber IsNot Nothing Then
Console.WriteLine("version # {0}, ", versionNumber)
End If
' Update the postal code attribute.
retrievedAccount.Address1_PostalCode = "98052"
' The address 2 postal code was set accidentally, so set it to null.
retrievedAccount.Address2_PostalCode = Nothing
' Shows usage of option set (picklist) enumerations defined in OptionSets.cs.
retrievedAccount.Address1_AddressTypeCode = New OptionSetValue(CInt(Fix(AccountAddress1_AddressTypeCode.Primary)))
retrievedAccount.Address1_ShippingMethodCode = New OptionSetValue(CInt(Fix(AccountAddress1_ShippingMethodCode.DHL)))
retrievedAccount.IndustryCode = New OptionSetValue(CInt(Fix(AccountIndustryCode.AgricultureandNonpetrolNaturalResourceExtraction)))
' Shows use of a Money value.
retrievedAccount.Revenue = New Money(5000000)
' Shows use of a Boolean value.
retrievedAccount.CreditOnHold = False
' Shows use of EntityReference.
retrievedAccount.ParentAccountId = New EntityReference(Account.EntityLogicalName, _parentAccountId)
' Shows use of Memo attribute.
retrievedAccount.Description = "Account for Fourth Coffee."
' Update the account record.
_serviceProxy.Update(retrievedAccount)
Console.WriteLine("and updated.")
DeleteRequiredRecords(promptforDelete)
End Using

The following example shows how to use the Create method to create an account record (late bound). For this sample to work correctly, you must be connected to the server to instantiate an IOrganizationService interface. You can find the complete sample in the sample code package in the folder SampleCode\CS\GeneralProgramming\LateBound\CRUDOperationsDE.cs.

' Instaniate an account object.
Dim account As New Entity("account")
' Set the required attributes. For account, only the name is required.
' See the Entity Metadata topic in the SDK documentatio to determine
' which attributes must be set for each entity.
account("name") = "Fourth Coffee"
' Create an account record named Fourth Coffee.
_accountId = _service.Create(account)
Console.Write("{0} {1} created, ", account.LogicalName, account.Attributes("name"))
' Create a column set to define which attributes should be retrieved.
Dim attributes As New ColumnSet(New String() { "name", "ownerid" })
' Retrieve the account and its name and ownerid attributes.
account = _service.Retrieve(account.LogicalName, _accountId, attributes)
Console.Write("retrieved, ")
' Update the postal code attribute.
account("address1_postalcode") = "98052"
' The address 2 postal code was set accidentally, so set it to null.
account("address2_postalcode") = Nothing
' Shows use of Money.
account("revenue") = New Money(5000000)
' Shows use of boolean.
account("creditonhold") = False
' Update the account.
_service.Update(account)
Console.WriteLine("and updated.")
' Delete the account.
Dim deleteRecords As Boolean = True
If promptForDelete Then
Console.WriteLine(vbLf & "Do you want these entity records deleted? (y/n) [y]: ")
Dim answer As String = Console.ReadLine()
deleteRecords = (answer.StartsWith("y") OrElse answer.StartsWith("Y") OrElse answer = String.Empty)
End If
If deleteRecords Then
_service.Delete("account", _accountId)
Console.WriteLine("Entity record(s) have been deleted.")
End If

Remarks

Message Availability

This message works regardless whether the caller is connected to the server or offline.

Not all entity types support this message offline. See Supported Entities later in this topic.

Privileges and Access Rights

To perform this action, the caller must have privileges on the entity that is specified in the entity parameter. For a list of the required privileges, see Create Privileges.

Notes for Callers

This method creates one record in a transaction. To create a record that has related records in a transaction, use CreateRequest.

By default the caller becomes the owner for the new record. However, for the caller to own the new record, it must have both Create and Read privileges for the entity. For more information, see Privileges by Entity. Alternatively, you can set the ownerid property to the ID of another user.

The entity instance that is specified as a parameter must contain values for all the attributes where the RequiredLevel is set to SystemRequired. You can see this in the metadata topic for the entity. If the entity instance includes properties where IsValidForCreate is false, the values are ignored. You can find this information in the metadata for your organization. See the preceding metadata browser information.

You can use this method to create any record of an entity that supports the Create message, including custom entities.

The following table shows the default entities that support this message. For the listed entities of this message, the Availability column shows Server if the caller must be connected to the server and shows Both if the caller can be either connected to, or disconnected from, the server.

Entity

Availability

account

Both

activitymimeattachment

Both

annotation

Both

annualfiscalcalendar

Both

appointment

Both

asyncoperation

Server

attributemap

Server

businessunit

Server

businessunitnewsarticle

Both

calendar

Both

campaign

Both

campaignactivity

Both

campaignresponse

Both

columnmapping

Both

competitor

Both

connection

Both

connectionrole

Both

connectionroleobjecttypecode

Both

constraintbasedgroup

Both

contact

Both

contract

Both

contractdetail

Both

contracttemplate

Server

customeraddress

Both

customeropportunityrole

Both

customerrelationship

Both

discount

Server

discounttype

Server

duplicaterule

Server

duplicaterulecondition

Server

email

Both

equipment

Server

fax

Both

fieldpermission

Server

fieldsecurityprofile

Server

fixedmonthlyfiscalcalendar

Both

goal

Server

goalrollupquery

Server

import

Both

importentitymapping

Both

importfile

Both

importjob

Both

importmap

Both

incident

Both

incidentresolution

Both

invoice

Both

invoicedetail

Both

isvconfig

Server

kbarticle

Both

kbarticlecomment

Both

kbarticletemplate

Both

lead

Both

letter

Both

list

Both

lookupmapping

Both

mailmergetemplate

Both

metric

Server

monthlyfiscalcalendar

Both

msdyn_postalbum

Server

msdyn_postconfig

Server

msdyn_postruleconfig

Server

opportunity

Both

opportunityclose

Both

opportunityproduct

Both

orderclose

Both

organizationui

Server

ownermapping

Both

phonecall

Both

picklistmapping

Both

pluginassembly

Server

plugintype

Server

post

Server

postcomment

Server

postfollow

Server

postlike

Server

pricelevel

Server

principalobjectattributeaccess

Server

processsession

Both

product

Server

productpricelevel

Server

publisher

Server

publisheraddress

Server

quarterlyfiscalcalendar

Both

queue

Server

queueitem

Both

quote

Both

quoteclose

Both

quotedetail

Both

recurrencerule

Server

recurringappointmentmaster

Both

relationshiprole

Both

relationshiprolemap

Both

report

Server

reportcategory

Server

reportentity

Server

reportvisibility

Server

resourcespec

Both

role

Server

rollupfield

Server

salesliterature

Server

salesliteratureitem

Server

salesorder

Both

salesorderdetail

Both

savedquery

Server

savedqueryvisualization

Server

sdkmessageprocessingstep

Server

sdkmessageprocessingstepimage

Server

sdkmessageprocessingstepsecureconfig

Server

semiannualfiscalcalendar

Both

service

Server

serviceappointment

Both

serviceendpoint

Server

sharepointdocumentlocation

Server

sharepointsite

Server

site

Server

solution

Server

subject

Both

systemform

Server

systemuser

Server

task

Both

team

Server

template

Both

territory

Server

transactioncurrency

Server

transformationmapping

Both

transformationparametermapping

Both

uom

Server

uomschedule

Both

userentityinstancedata

Both

userentityuisettings

Both

userform

Server

userquery

Both

userqueryvisualization

Both

webresource

Server

workflow

Server

workflowdependency

Server

workflowlog

Server

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.