Forum Discussion

ianthegeordie1892's avatar
ianthegeordie1892
Copper Contributor
Feb 07, 2024

JSON Form Header Date Calculation

Hi,

 

I want to display a message in the form header when a selected date is within 90 days. I have trying comparing with @now and adding 90 days but the calculation doesn't seem to trigger. any ideas welcome    

 

6 Replies

  • ianthegeordie1892 Try using JSON like below in list form header layout: 

     

     

    {
        "elmType": "div",
        "txtContent": "=if(Number([$TargetDateForTrial]) == 0, '', if(Date([$TargetDateForTrial]) <= Date(addDays(@now,90)),'OK','Please select date within 90 days.'))"
    }

     

     

    Where [$TargetDateForTrial] is an internal name of your date column in SharePoint list in this format: [$InternalNameOfColumn]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

     

    Here, I have used Number([$TargetDateForTrial]) == 0 to check if SharePoint date column is blank or not. You can find other ways to check if SharePoint date & time column is empty or not atSharePoint JSON formatting: Check if date & time column is blank/empty


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

    • ianthegeordie1892's avatar
      ianthegeordie1892
      Copper Contributor
      Thanks for the reply. I have followed the example below and included it in the header JSON. Unfortunately it still doesn't seem to work. This on a new creation of the form when I select the date field value not sure if that make a difference or not
      • ganeshsanap's avatar
        ganeshsanap
        MVP

        ianthegeordie1892 What is the exact issue when you say "it still doesn't seem to work"? Can you add the screenshots of list form if possible?

         

        Is it not showing the text correctly or are you getting any error message or anything else?

         

        Are you using correct internal name of the date field as suggested above? 

         

        And yes, I have tested this on list form and it works for me. Here is the output: 


        Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources