Forum Discussion
AP_TC_ECASD
Jan 23, 2025Copper Contributor
New-MgBookingBusinessService CustomQuestions
Hi! I'm working my way though BookingBusiness with PowerShell, so please forgive me if this is obvious. I've tried combing documentation but nothing seems to work. I have this script, and first, I...
luchete
Jan 26, 2025Steel Contributor
Hello AP_TC_ECASD
It looks like you're getting the staff members and custom questions correctly, and you’re looping through the staff and trying to create a new booking service with custom questions. It seems to me that the issue may be specifically with how you're passing the CustomQuestions property in the New-MgBookingBusinessService call.
I would try to modify the way you construct the CustomQuestions property in $serviceParams. Try using a New-Object to create proper objects rather than creating hashtables like:
CustomQuestions = $allCustomQuestions | ForEach-Object {
New-Object PSObject -Property @{
Id = $_.Id
IsRequired = $true # or $false depending on your requirement
}
}
I think this will ensure that each custom question is represented as an object rather than a simple hashtable.
You can also add a debug printout to see the structure of the CustomQuestions that you are sending with this line of code:
Write-Host "Custom Questions being sent: $($serviceParams.CustomQuestions)" -ForegroundColor Cyan
This way, you can confirm that the CustomQuestions is being built correctly before making the New-MgBookingBusinessService call.
Hope this helps!
- AP_TC_ECASDJan 27, 2025Copper Contributor
That worked!!!
Part 2 of this... I know how to Get-MgBookingBusinessAppointment but how do I get the customer responses to the Custom Questions?
- lucheteJan 27, 2025Steel Contributor
Hi AP_TC_ECASD
Nice hear that worked! Now for getting the customer responses to the custom questions, probably i'll try to use the Get-MgBookingBusinessAppointment command to fetch the appointment details. Them, after that, the responses to the custom questions will be part of the CustomQuestions property in the appointment object.Here’s a way to try to get the responses:
$appointmentId = "your-appointment-id" # Replace with the actual appointment ID $appointment = Get-MgBookingBusinessAppointment -BookingBusinessId $bookingBusinessId -AppointmentId $appointmentId # Display the custom questions and responses $appointment.CustomQuestions | ForEach-Object { Write-Host "Question: $($_.DisplayName), Response: $($_.Answer)" -ForegroundColor Green }
You only have to replace $appointmentId with the ID of the appointment you're interested in, and this should give you the responses to the custom questions for that appointment. I think this may work. Let me know how it goes!
- AP_TC_ECASDJan 27, 2025Copper Contributor
luchete Hmmmm... it comes back like this:
PS C:\Users\XXXXXX> $bookingBusinessId = "MYBOOKINGSBUSINESSID" $bookingAppointmentId = "AAMkAGYxMDIzZDRkLTAwMGUtNGQwNS05ZTZiLTdjNTE1NjQzYTI3ZABGAAAAAADIMrXgMknYSZZkpJugZS9XBwCa04VGcf1RTZr1hfB7M9VMAAAAAAENAACa04VGcf1RTZr1hfB7M9VMAAAHDGRNAAA=" # Retrieve the appointment details $appointment = Get-MgBookingBusinessAppointment -BookingBusinessId $bookingBusinessId -BookingAppointmentId $bookingAppointmentId # Display the custom questions and responses $appointment.CustomQuestions | ForEach-Object { Write-Host "Question: $($_.DisplayName), Response: $($_.Answer)" -ForegroundColor Green } Question: , Response:
Do you think the responses are in CustomerNotes somehow?TypeName: Microsoft.Graph.PowerShell.Models.MicrosoftGraphBookingAppointment Name MemberType Definition ---- ---------- ---------- Add Method void Add(string key, System.Object value), void IAssociativeArray[Object].Add(string ... Clear Method void Clear(), void IAssociativeArray[Object].Clear() ContainsKey Method bool ContainsKey(string key), bool IAssociativeArray[Object].ContainsKey(string key) CopyFrom Method void CopyFrom(System.Collections.IDictionary source), void CopyFrom(psobject source) Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() Remove Method bool Remove(string key), bool IAssociativeArray[Object].Remove(string key) ToJson Method Microsoft.Graph.PowerShell.Runtime.Json.JsonNode ToJson(Microsoft.Graph.PowerShell.Ru... ToJsonString Method string ToJsonString() ToString Method string ToString() TryGetValue Method bool TryGetValue(string key, [ref] System.Object value), bool IAssociativeArray[Objec... Validate Method System.Threading.Tasks.Task Validate(Microsoft.Graph.PowerShell.Runtime.IEventListene... EntityItem ParameterizedProperty System.Object EntityItem(string index) {get;set;} Item ParameterizedProperty System.Object IAssociativeArray[Object].Item(string index) {get;set;} AdditionalInformation Property string AdditionalInformation {get;set;} AdditionalProperties Property System.Collections.Generic.IDictionary[string,System.Object] AdditionalProperties {get;} AnonymousJoinWebUrl Property string AnonymousJoinWebUrl {get;set;} AppointmentLabel Property string AppointmentLabel {get;set;} CreatedDateTime Property System.Nullable[datetime] CreatedDateTime {get;set;} CustomerEmailAddress Property string CustomerEmailAddress {get;set;} CustomerName Property string CustomerName {get;set;} CustomerNotes Property string CustomerNotes {get;set;} CustomerPhone Property string CustomerPhone {get;set;} Customers Property Microsoft.Graph.PowerShell.Models.IMicrosoftGraphBookingCustomerInformationBase[] Cus... CustomerTimeZone Property string CustomerTimeZone {get;set;} Duration Property System.Nullable[timespan] Duration {get;} EndDateTime Property Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDateTimeZone EndDateTime {get;set;} FilledAttendeesCount Property System.Nullable[int] FilledAttendeesCount {get;} Id Property string Id {get;set;} IsCustomerAllowedToManageBooking Property System.Nullable[bool] IsCustomerAllowedToManageBooking {get;set;} IsLocationOnline Property System.Nullable[bool] IsLocationOnline {get;set;} JoinWebUrl Property string JoinWebUrl {get;set;} LastUpdatedDateTime Property System.Nullable[datetime] LastUpdatedDateTime {get;set;} MaximumAttendeesCount Property System.Nullable[int] MaximumAttendeesCount {get;set;} OptOutOfCustomerEmail Property System.Nullable[bool] OptOutOfCustomerEmail {get;set;} PostBuffer Property System.Nullable[timespan] PostBuffer {get;set;} PreBuffer Property System.Nullable[timespan] PreBuffer {get;set;} Price Property System.Nullable[double] Price {get;set;} PriceType Property System.Nullable[Microsoft.Graph.PowerShell.Support.BookingPriceType] PriceType {get;s... Reminders Property Microsoft.Graph.PowerShell.Models.IMicrosoftGraphBookingReminder[] Reminders {get;set;} SelfServiceAppointmentId Property string SelfServiceAppointmentId {get;set;} ServiceId Property string ServiceId {get;set;} ServiceLocation Property Microsoft.Graph.PowerShell.Models.IMicrosoftGraphLocation ServiceLocation {get;set;} ServiceName Property string ServiceName {get;set;} ServiceNotes Property string ServiceNotes {get;set;} SmsNotificationsEnabled Property System.Nullable[bool] SmsNotificationsEnabled {get;set;} StaffMemberIds Property string[] StaffMemberIds {get;set;} StartDateTime Property Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDateTimeZone StartDateTime {get;set;}