【Tips!】フロー(Flow)で週末(土日)を判定し平日だけ処理を実行する方法

スポンサーリンク

本日のTips!は、標準のフローだけを使って、開発なし(ノンコーティング)で休日を判定し、平日だけ処理を実行する方法をご紹介します。

お客様の業務を自動化する場合に、平日だけ処理を実行したいというご要望がよくありますが、この方法を使えば簡単に実現することができますので、是非マスターしてください。

スポンサーリンク

※祝日も判定して営業日だけ処理をする方法については、最後にご紹介いたします。

例えば、平日の毎朝8時に期日切れタスクがあるかチェックして、期日超過がある場合には担当者へメール通知するなどの用途があります。

ポイント

  • フロービルダーによるスケジュールトリガーフローの作成方法
  • フローを使った週末(土曜日・日曜日)の判定方法

1.フロービルダーを使って週末を判定してみよう

今回は、スケジュールトリガーフローを使って、曜日を判定する処理を作成してみます。もちろんスケジュールトリガー以外のフローでも構いません。

大まかな処理の流れは以下の通りです。

簡単な流れ

  • フロー実行日を使って曜日を判断する変数を定義
  • 曜日の変数を条件にして条件分岐処理を作成
  • デバッグ実行
  • フローの有効化とスケジュール設定

では、一つ一つ手順の内容を解説していきたいと思います。

1.フローの実行日を使って曜日を判断する変数を定義

1.Salesforceにログインして、[設定] からクイック検索で[フロー]を検索して実行します。

[新規フロー]のボタンをクリックして、新規フロー作成画面を開きます。

2.新規フロー画面では、スケジュールトリガーフローを選択します。

作成方法で表示される自由形式と自由レイアウト(Beta)はどちらでもお好きなものを選択してください。

3.スケジュールを設定をクリックして、スケジュール設定画面を表示します。

①開始日と開始時間を入力します。指定された開始日、開始時間でスケジュールが起動します。

※開始時間は、組織のタイムゾーンの時間で実行されます。

組織のタイムゾーンが海外になっている場合、日本の時間で設定すると期待した時間に動作しないため注意が必要となります。

②頻度を指定します。※今回は週末判定のテストフローを作成し、デバッグ実行で確認するだけのため、1回のみとします。

4.新規リソースをクリックし、曜日を判定するための変数を定義します。

リソース種別:数式 API参照名、説明:自由に定義してください。

データ型:数値 ※少数は0としてください。

数式は以下の内容を設定します。

MOD( {!$Flow.CurrentDate} – DATE(1900, 1, 7), 7)

上記数式により、フロー実行日の曜日が以下の0~6の数値で判定されます。

  • 0:日曜日
  • 1:月曜日
  • 2:火曜日
  • 3:水曜日
  • 4:木曜日
  • 5:金曜日
  • 6:土曜日

2.曜日の変数を条件にして条件分岐処理を作成

1.続いて、要素を追加から、ロジック[決定]をクリックして、週末判定のロジックを作成します。

2.週末(土曜日・日曜日)を判定する処理を以下の内容で作成します。

結果:週末(土日) 表示ラベル:週末(土日) API名は自由に定義ください。

結果を実行する条件の要件:いずれかの条件に一致(OR)を選択し以下2つの条件を追加

  1. リソース:DayOfTheWeekDecimal 演算子:次の文字列と一致しない 値:0
  2. リソース:DayOfTheWeekDecimal 演算子:次の文字列と一致しない 値:6

曜日判定の数式を使って、フロー実行日が0(日曜日)、または6(土曜日)のどちらかの場合は、週末(土日)と判断します。

もう一方のデフォルトの結果に関しては、ラベルを平日と定義 ※ロジックは不要

3.営業日を最終的に判断するための新規リソースを追加して、以下の変数を定義します。

変数名:BusinessDayFlag (ご自由に定義してください)

データ型:Boolean デフォルト値:{!GlobalConstant.True} ※グローバル変数のTrueをセット(Trueで検索すると候補に表示されます)

4.週末判定処理の分岐で、週末判定された場合の後続フローで以下のロジック[割り当て]を定義します。

※週末の場合に、3.で作成した週末変数フラグにTrueをセットします。

変数:BusinessDayFlag 演算子:次の文字列と一致する 値:Global変数のFalseをセット

5.週末判定ロジックの完了

最終的に以下のようなフローが作成されます。

上記サンプルでは、スケジュール実行時の日付を使って、週末(土日)の判定が行われます。

週末判定処理の平日の後続フローに実行したい処理やサブフローの呼び出しを定義することで平日だけ処理を行うことができます。

また、今回のサンプルでは、1回だけの繰り返しとしましたが、スケジュールを毎日繰り返し処理として定義すれば平日の日次処理を作成することができます。

3.デバッグ実行

1.フローを保存したあと、デバッグボタンをクリックします。

フローをデバッグの画面が表示されます。今回作成したフローは特に処理を入れていないためロールバックの必要はありませんが、

データを作成したりするような処理がある場合は、ロールバックオードを利用して既存データに影響しないように実行することもできます。

2.実行結果の確認

デバッグ実行すると処理結果の詳細を確認することができます。上記ではご説明していませんが、以下の図の最後に表示されているような変数の値などを表示するメモを追加するとデバッグしやすくなりますので、ぜひお試しください。

※処理の最後にメモなどのアクションを定義するだけです。

4.フローの有効化とスケジュール設定

1.デバッグ実行で問題がなければ、上記で作成したフローを保存した後、有効化ボタンをクリックしてください。

2.フローを有効化すると、スケジュール済みジョブに実行計画が登録されます。

例では、2月14日の21:45に次回実行される予定で登録されています。

※スケジュールを変更したい場合は、フローのスケジュールを変更して保存後、有効化することで新しいスケジュールに変更することができます。

サンプルフロー(メタデータ)

本記事でご紹介したフローのメタデータを公開します。

<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <actionCalls>
        <name>DebugMemo</name>
        <label>営業日判定結果</label>
        <locationX>358</locationX>
        <locationY>1164</locationY>
        <actionName>NewNote</actionName>
        <actionType>quickAction</actionType>
        <inputParameters>
            <name>Title</name>
            <value>
                <stringValue>営業日判定</stringValue>
            </value>
        </inputParameters>
        <inputParameters>
            <name>Body</name>
            <value>
                <stringValue>日付:{!$Flow.CurrentDate} 曜日判定:{!DayOfTheWeekDecimal} 営業日判定:{!BusinessDayFlag}</stringValue>
            </value>
        </inputParameters>
    </actionCalls>
    <apiVersion>50.0</apiVersion>
    <assignments>
        <name>SetBusinessDayFlagFalse</name>
        <label>営業日フラグにFalseをセット</label>
        <locationX>50</locationX>
        <locationY>396</locationY>
        <assignmentItems>
            <assignToReference>BusinessDayFlag</assignToReference>
            <operator>Assign</operator>
            <value>
                <booleanValue>false</booleanValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>DebugMemo</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>SetBusinessDayFlagFalse_0</name>
        <label>営業日フラグにFalseをセット</label>
        <locationX>754</locationX>
        <locationY>756</locationY>
        <assignmentItems>
            <assignToReference>BusinessDayFlag</assignToReference>
            <operator>Assign</operator>
            <value>
                <booleanValue>false</booleanValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>LoopHolidayRecords</targetReference>
        </connector>
    </assignments>
    <decisions>
        <description>祝日判定処理</description>
        <name>ConditionJudgementHolidays</name>
        <label>祝日判定処理</label>
        <locationX>886</locationX>
        <locationY>636</locationY>
        <defaultConnector>
            <targetReference>LoopHolidayRecords</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>営業日</defaultConnectorLabel>
        <rules>
            <name>IsHoliday</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Flow.CurrentDate</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <elementReference>LoopHolidayRecords.ActivityDate</elementReference>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>SetBusinessDayFlagFalse_0</targetReference>
            </connector>
            <label>祝日</label>
        </rules>
    </decisions>
    <decisions>
        <description>週末(土日)判定処理
0:日曜日、6:土曜日</description>
        <name>ConditionJudgementIsWeekend</name>
        <label>週末(土日)判定処理</label>
        <locationX>358</locationX>
        <locationY>276</locationY>
        <defaultConnector>
            <targetReference>GetOrgHolidayRecords</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>平日</defaultConnectorLabel>
        <rules>
            <name>IsWeekend</name>
            <conditionLogic>or</conditionLogic>
            <conditions>
                <leftValueReference>DayOfTheWeekDecimal</leftValueReference>
                <operator>NotEqualTo</operator>
                <rightValue>
                    <numberValue>0.0</numberValue>
                </rightValue>
            </conditions>
            <conditions>
                <leftValueReference>DayOfTheWeekDecimal</leftValueReference>
                <operator>NotEqualTo</operator>
                <rightValue>
                    <numberValue>6.0</numberValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>SetBusinessDayFlagFalse</targetReference>
            </connector>
            <label>週末(土日)</label>
        </rules>
    </decisions>
    <formulas>
        <description>曜日判定のための変数</description>
        <name>DayOfTheWeekDecimal</name>
        <dataType>Number</dataType>
        <expression>MOD( {!$Flow.CurrentDate} - DATE(1900, 1, 7), 7)</expression>
        <scale>0</scale>
    </formulas>
    <interviewLabel>営業日判定フロー {!$Flow.CurrentDateTime}</interviewLabel>
    <label>営業日判定フロー</label>
    <loops>
        <name>LoopHolidayRecords</name>
        <label>祝日分繰り返し処理 (LoopHolidayRecords)</label>
        <locationX>666</locationX>
        <locationY>516</locationY>
        <collectionReference>GetOrgHolidayRecords</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>ConditionJudgementHolidays</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>DebugMemo</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>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>GetOrgHolidayRecords</name>
        <label>組織の休日レコード取得</label>
        <locationX>666</locationX>
        <locationY>396</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>LoopHolidayRecords</targetReference>
        </connector>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>Holiday</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <start>
        <locationX>232</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>ConditionJudgementIsWeekend</targetReference>
        </connector>
        <schedule>
            <frequency>Once</frequency>
            <startDate>2021-02-14</startDate>
            <startTime>00:00:00.000Z</startTime>
        </schedule>
        <triggerType>Scheduled</triggerType>
    </start>
    <status>Active</status>
    <variables>
        <description>平日判定フラグ</description>
        <name>BusinessDayFlag</name>
        <dataType>Boolean</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
        <value>
            <booleanValue>true</booleanValue>
        </value>
    </variables>
</Flow>

 

上記、このソースの前半部分が平日判定の内容となります。

まとめ

Processed with VSCO with f1 preset

いかがでしたでしょうか。説明した手順で設定はうまくいきましたか?

今回は、週末を判定するだけでしたが、週末及び祝日を判定して営業日だけ処理を実行する方法もあります。

そのやり方は、以下の記事で紹介していますので、興味があればご覧ください

スポンサーリンク

「【Tips!】フロー(Flow)で週末(土日)を判定し平日だけ処理を実行する方法」への66件のフィードバック

  1. You really make it seem so easy along with your presentation but I to find this matter to be really
    one thing that I feel I would never understand.
    It kind of feels too complex and extremely vast for me.

    I am looking forward on your next post, I will try to get the
    hang of it! Escape rooms

  2. Oh my goodness! Incredible article dude! Thank you so much, However I am encountering issues with your RSS. I don’t understand the reason why I am unable to subscribe to it. Is there anyone else having the same RSS problems? Anyone who knows the solution will you kindly respond? Thanx!!

  3. Good post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always useful to read through articles from other authors and practice something from their websites.

  4. Next time I read a blog, I hope that it doesn’t fail me as much as this particular one. I mean, Yes, it was my choice to read through, however I truly thought you’d have something interesting to say. All I hear is a bunch of moaning about something you could fix if you weren’t too busy seeking attention.

  5. I’m amazed, I must say. Seldom do I encounter a blog that’s both educative and amusing, and without a doubt, you’ve hit the nail on the head. The issue is something which too few men and women are speaking intelligently about. I’m very happy that I came across this during my hunt for something concerning this.

  6. Aw, this was a very good post. Taking a few minutes and actual effort to generate a top notch article… but what can I say… I hesitate a lot and never seem to get anything done.

  7. Greetings, I do believe your website may be having internet browser compatibility problems. Whenever I take a look at your website in Safari, it looks fine however when opening in Internet Explorer, it has some overlapping issues. I just wanted to provide you with a quick heads up! Besides that, excellent blog.

  8. Your style is so unique in comparison to other people I’ve read stuff from. Thank you for posting when you have the opportunity, Guess I’ll just book mark this blog.

  9. Oh my goodness! Impressive article dude! Many thanks, However I am going through issues with your RSS. I don’t know why I can’t join it. Is there anybody having identical RSS issues? Anybody who knows the answer can you kindly respond? Thanx.

  10. Hello there! This post could not be written any better! Looking through this post reminds me of my previous roommate! He always kept talking about this. I am going to send this post to him. Fairly certain he’s going to have a great read. I appreciate you for sharing!

  11. Incorporating Sugar Protector into my daily regimen has been a game-changer for my overall health.
    As a person that currently focuses on healthy and balanced eating, this
    supplement has actually offered an added increase of protection. in my energy degrees,
    and my wish for undesirable treats so easy can have such an extensive impact on my
    daily life.

  12. Incorporating Sugar Protector into my day-to-day regimen has actually been a game-changer for my general wellness.
    As somebody that currently focuses on healthy and balanced eating, this supplement has offered an added
    boost of defense. in my energy degrees, and my wish for harmful
    treats so easy can have such an extensive influence on my every day life.

  13. Uncovering Sugar Defender has actually been a game-changer for me, as
    I have actually always been vigilant regarding managing my blood sugar levels.
    I currently really feel encouraged and confident in my ability to preserve
    healthy and balanced degrees, and my most current checkup have actually reflected this progress.

    Having a trustworthy supplement to complement my a significant source of comfort, and I’m truly glad for
    the substantial distinction Sugar Defender has made in my general health.

  14. Integrating Sugar Defender into my daily routine has been a game-changer for my total health.

    As someone who already focuses on healthy eating, this supplement has actually provided an included
    boost of protection. in my power degrees, and my need for harmful snacks so easy can have such a profound effect on my every day life.

  15. Uncovering Sugar Defender has actually been a game-changer
    for me, as I’ve always been vigilant regarding managing
    my blood sugar levels. With this supplement, I feel equipped to take charge of my
    wellness, and my latest clinical exams have actually reflected
    a significant turnaround. Having a credible ally in my corner supplies me with a complacency
    and peace of mind, and I’m deeply happy for the extensive difference Sugar Protector has made in my well-being.

  16. I blog often and I seriously thank you for your information. The article has truly peaked my interest. I will book mark your blog and keep checking for new information about once a week. I opted in for your Feed too.

  17. You are so interesting! I don’t think I’ve read through anything like that before. So good to find another person with genuine thoughts on this issue. Really.. thank you for starting this up. This website is one thing that’s needed on the internet, someone with a bit of originality.

  18. Hi there! Do you know if they make any plugins to assist with Search Engine
    Optimization? I’m trying to get my website to rank for some targeted keywords but I’m not seeing very
    good results. If you know of any please share. Thanks! You can read similar article here:
    Eco wool

  19. Hello! I could have sworn I’ve been to your blog before but after going through a few of the posts I realized it’s new to me. Regardless, I’m definitely pleased I stumbled upon it and I’ll be bookmarking it and checking back regularly!

コメントは受け付けていません。

上部へスクロール