0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

選択リストの「年」「月」「日」の値を日付項目に落とし込む方法(Lightning環境なら設定注意)

Last updated at Posted at 2021-04-03

こんにちは。本橋です!

今回は選択リスト「年」「月」「日」の値を日付項目に落とし込む方法をお伝えします。

つまりこんな感じです
年0403.png

選択リストで年項目作成。(API参照名はYear__c)
他に選択リストで月項目作成(API参照名はMonth__c)
選択リストで項目日項目作成(API参照名はDay__c)

上記3つの選択リストに基づき数式で日付項目として表示できます
年04022.png

数式は下記となります

DATEVALUE(LEFT(TEXT(Year__c), 4) & "-" & MID(TEXT(Month__c), 1, 2) & "-" & RIGHT(TEXT(Day__c), 2))

注意点としては「2021年2月30日」など存在しない月日を選択すれば数式はエラーとなりますのでお気を付けください。
classic環境0403.png

Classic環境なら「#エラー」と表示されますがLightning環境なら下記のようなエラーが表示されてしまいページレイアウトそのものが見えなくなります。
lightningエラー0403.png

なので、Lightning環境でこの設定を行うのは注意が必要です。

応用編
下記のように値を「令和3年」と設定すれば、選択リストは令和で選択し、日付を西暦に変換することが可能です
令和変換0403.png

以上のようにLightningならエラー表示が出て危険な設定なので、くれぐれも設定にはご注意ください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?