<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <actionCalls>
        <name>Parse_Shifts</name>
        <label>Parse Shifts</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <actionName>mdpick__MultiDatePickParser</actionName>
        <actionType>apex</actionType>
        <connector>
            <targetReference>Loop_Shifts</targetReference>
        </connector>
        <inputParameters>
            <name>jsonStrings</name>
            <value>
                <elementReference>varPickedJson</elementReference>
            </value>
        </inputParameters>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </actionCalls>
    <apiVersion>63.0</apiVersion>
    <assignments>
        <name>Build_Shift</name>
        <label>Build Shift</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <assignmentItems>
            <assignToReference>varShift.mdpick__Schedule_Date__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>Loop_Shifts.fromDate</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>varShift.mdpick__Start_Time__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>Loop_Shifts.startTime</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>varShift.mdpick__End_Time__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>Loop_Shifts.endTime</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>varShift.mdpick__Event__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>recordId</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>varShift.mdpick__Schedule_Name__c</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue>Shift</stringValue>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>colShifts</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>varShift</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_Shifts</targetReference>
        </connector>
    </assignments>
    <description>Starter flow from the MultiDatePick blog (Flow loops). Pick shift dates and times on one screen, then save one Schedule record per shift in a single Create Records step after the loop. Launch it from an Event record to link every shift to that record (recordId). Set the calendar's Config Name on the Pick Shifts screen, and swap the object and fields for your own.</description>
    <interviewLabel>MDP Starter - Add Shifts {!$Flow.CurrentDateTime}</interviewLabel>
    <label>MDP Starter - Add Shifts</label>
    <loops>
        <name>Loop_Shifts</name>
        <label>Loop Shifts</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <collectionReference>Parse_Shifts.data</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Build_Shift</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Save_Shifts</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>AUTO_LAYOUT_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processType>Flow</processType>
    <recordCreates>
        <name>Save_Shifts</name>
        <label>Save Shifts</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>Done</targetReference>
        </connector>
        <inputReference>colShifts</inputReference>
    </recordCreates>
    <screens>
        <name>Done</name>
        <label>Done</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <allowBack>false</allowBack>
        <allowFinish>true</allowFinish>
        <allowPause>false</allowPause>
        <fields>
            <name>Done_Text</name>
            <fieldText>&lt;p&gt;Shifts saved.&lt;/p&gt;</fieldText>
            <fieldType>DisplayText</fieldType>
        </fields>
        <showFooter>true</showFooter>
        <showHeader>true</showHeader>
    </screens>
    <screens>
        <name>Pick_Shifts</name>
        <label>Pick Shifts</label>
        <locationX>0</locationX>
        <locationY>0</locationY>
        <allowBack>false</allowBack>
        <allowFinish>true</allowFinish>
        <allowPause>false</allowPause>
        <connector>
            <targetReference>Parse_Shifts</targetReference>
        </connector>
        <fields>
            <name>Shift_Calendar</name>
            <extensionName>mdpick:multiDatePickDateTime</extensionName>
            <fieldType>ComponentInstance</fieldType>
            <inputParameters>
                <name>outputAsJson</name>
                <value>
                    <booleanValue>true</booleanValue>
                </value>
            </inputParameters>
            <isRequired>true</isRequired>
            <outputParameters>
                <assignToReference>varPickedJson</assignToReference>
                <name>selectedDatesWithTimesJson</name>
            </outputParameters>
        </fields>
        <showFooter>true</showFooter>
        <showHeader>true</showHeader>
    </screens>
    <start>
        <locationX>50</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>Pick_Shifts</targetReference>
        </connector>
    </start>
    <status>Draft</status>
    <variables>
        <name>colShifts</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>mdpick__Schedule__c</objectType>
    </variables>
    <variables>
        <name>recordId</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>false</isOutput>
    </variables>
    <variables>
        <name>varPickedJson</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
    </variables>
    <variables>
        <name>varShift</name>
        <dataType>SObject</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>mdpick__Schedule__c</objectType>
    </variables>
</Flow>
