3 Replies Latest reply on Sep 15, 2018 3:11 PM by AlasdairRobertson

    Task Assignment Email - Using IF statement in HTML body?

    MarkLarvo Specialist

      Good day!

       

      I am struggling to get an if statement expression into our html email body. So far the only text that appears is the word "HELLO" in the Need By cell. HELLO was added just to confirm something was working.

       

      kesm - expression in html.png

      I was ok when the requests were simple but now they want fancy. The goal here is to read a location code stored in Incident or Service Request and use that code to convert the Need By date stored in the Task to the corresponding location time zone.

       

      My long term goal is to make this a global variable so it can be reused in multiple notifications without the need to edit all of them each time we add a new location. I am guessing it is a matter of missing "" or $().

       

      Here is a copy of the actual text:

      $(if [Incident#.]KE_ReportedForLocationCode in ("BJ", "HK", "SH") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("BJ", "HK", "SH")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "Asia/Hong_Kong"))

      else if [Incident#.]KE_ReportedForLocationCode in ("DE") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("DE")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "Europe/Berlin"))

      else if [Incident#.]KE_ReportedForLocationCode in ("UK") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("UK")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "Europe/London"))

      else if [Incident#.]KE_ReportedForLocationCode in ("BU", "DC", "NY") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("BU", "DC", "NY")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "America/New_York"))

      else if [Incident#.]KE_ReportedForLocationCode in ("CH", "DA", "HU") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("CH", "DA", "HU")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "America/Chicago"))

      else if [Incident#.]KE_ReportedForLocationCode in ("LA", "PA", "SF") ||

           [ServiceReq#.]KE_ReportedForLocationCode in ("LA", "PA", "SF")

                then DateTime(FormatDate(KE_ParentNeedBy, "MM/dd/yyyy hh:mm tt", "America/Los_Angeles"))

      else "EMPTY") HELLO

       

      I could not find any samples using IF inside an email body. Thanks for any suggestions! Mark.

        • 1. Re: Task Assignment Email - Using IF statement in HTML body?
          AlasdairRobertson ITSMMVPGroup

          Hi Mark

           

          You can use if statements in emails but I tend to use for simple things.  Could you not move the calculation to the parent object, do the work there and then just have a field pulled on to the email.  Then you can use lots of business rules and more complex functions if required to do the work and debugging?

           

          Alasdair

          • 2. Re: Task Assignment Email - Using IF statement in HTML body?
            MarkLarvo Specialist

            Alasdair,

             

            I like where you are headed with this... that makes more sense to store the right data in the parent and pass it to Task.

             

            We have not yet explored using DateTime fields with the timezone selector. Given that we have a distributed service desk structure, and self-service in the wings, it is something we are keen on introducing.

             

            The code above was for Task. Task gets the DateTime from the Parent.

             

            When I select a user a default location code is stored in the Parent. We have an override checkbox (Is Visiting) which allows an analyst to choose another location code.

             

            Question: If I turn on the TimeZone selector, could the selection of the location code in turn select the correct time zone for that field without overwriting any entered date/time?

             

            Now if I could do that and then pass that down to the the task it would be absolutely brilliant.

             

            Your feedback is always appreciated! Have a great weekend! Mark.

            • 3. Re: Task Assignment Email - Using IF statement in HTML body?
              AlasdairRobertson ITSMMVPGroup

              I haven't tried I am afraid, I would probably look to have a business rule that takes the current datetime from the parent and uses an expression with the new timezone field to calculate the desired timezone.