#powershell #dynamics-crm
#powershell #dynamics-crm
Вопрос:
Я хочу создать «Календарь обслуживания клиентов» в D365 с помощью команды PowerShell. Кто-нибудь может мне помочь? Заранее спасибо, я пробовал что-то подобное, могу создать календарь, а не calendarurle
$usercalendarid="4385DF09-D156-4D4E-BABE-E6548DF50B49"
$StandardBUid ="BCAF91CC-5D73-EA11-A811-000D3AB855E7"
$mainCalendarGuid="4385DF09-D156-4D4E-BABE-E6548DF50B49"
$innerCalendarGuid="9566ab3e-208f-40cb-9b01-35110efa1161"
$businessunit = Get-CrmRecord -conn $conn -EntityLogicalName businessunit -Id $StandardBUid -Fields name
$standardBUReference = New-CrmEntityReference -EntityLogicalName businessunit -Id $StandardBUid
$calendarTypeValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 1
$calendarid = New-Object -TypeName System.Guid $mainCalendarGuid
New-CrmRecord -conn $conn -EntityLogicalName calendar -Fields @{"name"="cale2";"type"=$calendarTypeValue;"businessunitid"=$standardBUReference;calendarid=$calendarid }
*-- Create innercalendar*
$innerscalendarid = New-Object -TypeName System.Guid $innerCalendarGuid
$calendarTypeValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList -1
New-CrmRecord -conn $conn -EntityLogicalName calendar -Fields @{"name"="inner";"businessunitid"=$standardBUReference; calendarid=$innerscalendarid }
-- Create calendarrule
$createdInnerCalendarReference = New-CrmEntityReference -EntityLogicalName calendar -Id $innerCalendarGuid
$createdMainCalendarReference = New-CrmEntityReference -EntityLogicalName calendar -Id $mainCalendarGuid
$timezoneValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 190
$entCollectioncalendarRules = New-Object Microsoft.Xrm.Sdk.EntityCollection
[Microsoft.Xrm.Sdk.Entity]$calendarRuleEntity = New-Object Microsoft.Xrm.Sdk.Entity
$calendarRuleEntity.LogicalName = 'calendarrule'
$calendarRuleEntity.Id= New-Object -TypeName System.Guid '9d3423b2-c69e-46db-9fde-b7f68784286c'
$calendarRuleEntity.Attributes['duration']=1234
$calendarRuleEntity.Attributes['calendarid']=$createdMainCalendarReference
$calendarRuleEntity.Attributes['innercalendarid']=$createdInnerCalendarReference
$calendarRuleEntity.Attributes['effort']=1.0;
$calendarRuleEntity.Attributes['extentcode']=1;
$calendarRuleEntity.Attributes['pattern'] = "FREQ=DAILY;COUNT=1"
$calendarRuleEntity.Attributes['rank']=0
$calendarRuleEntity.Attributes['timezonecode']=110
$calendarRuleEntity.Attributes['starttime'] = Get-Date
$calendarRuleEntity.Attributes['innercalendarid'] =$createdInnerCalendarReference
$calendarRuleEntity.Attributes['calendarid'] = $createdMainCalendarReference
$entCollectioncalendarRules.Entities.Add($calendarRuleEntity)
$entCollectioncalendarRules.Entities.Add($calendarRuleEntity1)
-- Update Calendarrule to calendar
$calendartobeUpdated = Get-CrmRecord -conn $conn -EntityLogicalName calendar -Id $innerCalendarGuid -Fields *
$calendartobeUpdated.name="Updated from powershell 2"
$calendartobeUpdated.calendarrules.Entities.Add($calendarRuleEntity)
Set-CrmRecord -conn $conn -CrmRecord $calendartobeUpdated
Комментарии:
1. Вы что-нибудь пробовали?