Site icon UnofficialSF

From Chris Albanese: Build your own appointment review screen

Do check out the existing possibilities to make changes to the appointment review screen before trying this out.

When you look at a Salesforce Scheduler flow, there’s a core action called saveAppointment. Did you ever wonder what it does, what the inputs are and whether you can tailor it?

What does it do?

It takes the values gathered during the flow interview and creates or updates a ServiceAppointment record and an associated AssignedResource record. If you provide optional attendees, it will also create AssignedResource records for each optional service resource id provided.

The help and training article is locate here, but let’s look at what’s inside the inputs provided this action.

What is contained in the input fields?

The easiest way to see what is passed into the Save Action is to run the flow in debug mode. There you will see the values that are stored into each field passed into the Save Action.

After you press finish, scroll up and check out what is in the Save Appointment step.

What do we see here?
Inputs:

Output:

How do these values get set?

In a Salesforce Scheduler flow, the Screen steps each have components on them that save values to variables in the flow. For example, the Select Location screen has a screen component that saves the Service Territory Id and Address fields to the corresponding fields in the ServiceAppointment variable, as you can see in the screen shot below.

But how does the serviceAppointmentFields variable get set?

This field is the bulk of what is passed into the Save Action.

It gets set by the Review Screen component that is located on the Review Screen.

What if I wanted to set the values for the serviceAppointmentFields variable myself?

So as I have written above, the Review Screen component is really a black box. It takes the fields from the review screen along with other fields in the ServiceAppointment object variable and the WorkTypeGroupId variable and creates a JSON string from them.

What is JSON you ask? You’ve probably heard of it and you can definitely Google it and find out more, but it’s essentially a collection of name:value pairs, and you see that in the debugger output above. It’s very powerful and allows you to store lots of rich information, including arrays, in a text field.

You can create your own JSON string using a formula field. You can pass that formula field into the Save Appointment action. Or you can assign it to the serviceAppointmentFields variable in an assignment step.

Here’s an example of a formula field that I have used to pass into the Save Appointment action:

'{"Description":"' &{!ServiceAppointment.Description}& 
'",'& '"SchedStartTime":"' & substitute(substitute(text({!ServiceAppointment.SchedStartTime}),' ','T'),'Z','.000Z')&
'",'& '"SchedEndTime":"' & substitute(substitute(text({!ServiceAppointment.SchedEndTime}),' ','T'),'Z','.000Z')&
'",'& '"Subject":"' & {!ServiceAppointment.Subject}&
'",'& '"AdditionalInformation":"' & {!ServiceAppointment.AdditionalInformation}&
'",'& '"AppointmentType":"' & text({!ServiceAppointment.AppointmentType})&
'",'& '"Comments":"' & {!ServiceAppointment.Comments}&
'",'& '"ParentRecordId":"' & {!ServiceAppointment.ParentRecordId}&
'",'& '"Street":"' & {!ServiceAppointment.Street}&
'",'& '"City":"' & {!ServiceAppointment.City}&
'",'& '"State":"' & {!ServiceAppointment.State}&
'",'& '"PostalCode":"' & {!ServiceAppointment.PostalCode}&
'",'& '"Country":"' & {!ServiceAppointment.Country}&
'",'& '"WorkTypeGroupId":"' & {!WorkTypeGroupId}&
'",'& '"ServiceTerritoryId":"' & {!ServiceAppointment.ServiceTerritoryId}&
'",'& '"ServiceResourceId":"' & {!ServiceResourceId}&
'",'& '"Phone":"' & {!ServiceAppointment.Phone}&
'",'& '"Email":"' & {!ServiceAppointment.Email}&
'",'& '"IsAnonymousBooking":"' & if({!ServiceAppointment.IsAnonymousBooking},"True","False")&
'",'& '"isSlotChanged":"' & "False"&
'"}'

What do you see in the field above?

Lot’s of care taken to make sure each name:value pair is enclosed in double quotes and that each pair has a colon between it and is separated by a comma from the next pair. And the whole string is wrapped in curly braces {}. Note the added complexity of the SchedStartTime and SchedEndTime fields, to convert them from datetime data types to a text type in a “”yyyy-MM-dd’T’HH:mm:ss.SSSZ”” format. I’ve also had to use a text() function to convert the picklist field called AppointmentType to a string value.

Can I replace the out of the box review screen with my own review screen?

Yes you can! You can display whatever content you like using standard flow components such as Display Text and you and capture user input using standard flow components such as Input Text or Date.

You just need to make sure you create the JSON string to pass into the Save Appointment action.

Minimum values required: make sure the at least the following fields are passed in order to get the desired results :

{"ParentRecordId": "001xx0000000000000",
"ServiceTerritoryId": "0Hhxx0000000000000",
"ServiceResourceId": "0Hnxx0000000000000",
"WorkTypeGroupId": "0VSxx0000000000000", (for new)
"WorkTypeId":"08qxx0000000000000" (for modify)
"SchedStartTime": "2021-02-21T20:30:00.000Z",
"SchedEndTime": "2021-02-21T21:00:00.000Z",
"IsAnonymousBooking": <VALUE SET IN FLOW VARIABLE>,
"isSlotChanged": <false for new, true for modify>,
"schedulingPolicyName": "<same policy name set in flow>"
}

Details of the Save Appointment inputs

Exit mobile version
Skip to toolbar