< Back

Add-CrmActivityToCrmRecord

Sat Jan 18, 2020 3:57 pm

NAME Add-CrmActivityToCrmRecord



SYNOPSIS

Create a new activity to a record.





SYNTAX

Add-CrmActivityToCrmRecord [-conn <CrmServiceClient>] [-CrmRecord] <PSObject> [-ActivityEntityType] <String>

[-Subject] <String> [-Description] <String> [-OnwerUserId] <String> [[-Fields] <Hashtable>] [<CommonParameters>]



Add-CrmActivityToCrmRecord [-conn <CrmServiceClient>] [-EntityLogicalName] <String> [-Id] <Guid>

[-ActivityEntityType] <String> [-Subject] <String> [-Description] <String> [-OnwerUserId] <String> [[-Fields]

<Hashtable>] [<CommonParameters>]





DESCRIPTION

The Add-CrmActivityToCrmRecord cmdlet lets you add an activity to a record. You use ActivityEntityType to specify

Activity Type and Subject/Description to set values.

You can use Fields optional Parameter to specify additional Field values. Use @{"field logical name"="value"}

syntax to create Fields , and make sure you specify correct type of value for the field.

You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition, for

CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.



There are two ways to specify a target record.



1. Pass EntityLogicalName and record's Id.

2. Get a record object by using Get-CrmRecord/Get-CrmRecords cmdlets, and pass it.



You can specify note subject and body by using -Subject and -NoteText parameters.





PARAMETERS

-conn <CrmServiceClient>

A connection to your CRM organization. Use $conn = Get-CrmConnection <Parameters> to generate it.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-CrmRecord <PSObject>

A record object which is obtained via Get-CrmRecord/Get-CrmRecords. When you pass CrmRecord, then you don't

use EntityLogicalName/Id.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-ActivityEntityType <String>

A logicalname for an Activity Entity to add. i.e.)phonecall, email, task, etc..



Required? true

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Subject <String>

Subject of the activity record.



Required? true

Position? 4

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Description <String>

Description of the activity record.



Required? true

Position? 5

Default value

Accept pipeline input? false

Accept wildcard characters? false



-OnwerUserId <String>





Required? true

Position? 6

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Fields <Hashtable>

A List of field name/value pair. Use @{"field logical name"="value"} syntax to create Fields, and make sure

you specify correct type of value for the field.

You can use Get-CrmEntityAttributeMetadata cmdlet and check AttributeType to see the field type. In addition,

for CRM specific types, you can use New-CrmMoney, New-CrmOptionSetValue or New-CrmEntityReference cmdlets.



Required? false

Position? 7

Default value

Accept pipeline input? false

Accept wildcard characters? false



-EntityLogicalName <String>

A logicalname of the target record. i.e.)account, contact, lead, etc..



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Id <Guid>

An Id (guid) of the record.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS









OUTPUTS









NOTES









-------------------------- Example 1 --------------------------



Add-CrmActivityToCrmRecord -conn $conn -EntityLogicalName account -Id feff5970-6317-e511-80da-c4346bc43d94

-ActivityEntityType task -Subject "sample task" -Description "sample task description" -OnwerUserId

f9d40920-7a43-4f51-9749-0549c4caf67d



This example adds a task an account record.







-------------------------- Example 2 --------------------------



Add-CrmActivityToCrmRecord account feff5970-6317-e511-80da-c4346bc43d94 task "sample task" "sample task

description" f9d40920-7a43-4f51-9749-0549c4caf67d



This example adds a task to an account record by omitting parameters names.

When omitting parameter names, you do not provide $conn, cmdlets automatically finds it.







-------------------------- Example 3 --------------------------



Add-CrmActivityToCrmRecord account feff5970-6317-e511-80da-c4346bc43d94 task "sample task" "sample task

description" f9d40920-7a43-4f51-9749-0549c4caf67d

@{"scheduledend"=(Get-Date).AddDays(3);"prioritycode"=New-CrmOptionSetValue 2}



This example adds a task to an account record with Due Date and Priority fields.







-------------------------- Example 4 --------------------------



PS C:\\>$account = Get-CrmRecord account feff5970-6317-e511-80da-c4346bc43d94 name



PS C:\\>user = Get-MyCrmUserId



PS C:\\>Add-CrmActivityToCrmRecord $account task "sample task" "sample task description" $user



This example retrieves and stores an account, and login user Id (guid) to variables. Then passes them to

Add-CrmActivityToCrmRecord.









RELATED LINKS