1

I am using page 28 of this doc for reference: https://resources.docs.salesforce.com/200/latest/en-us/sfdc/pdf/bi_dev_guide_saql.pdf

I need to change the time zone in the step. I am trying to use the computeExpression action to handle it. Here is the code I tried:

 "CreatedDate_Hour_3": {
            "datasets": [
                {
                    "id": "0Fb32000000TVRzCAO",
                    "label": "Case_Article_Survey",
                    "name": "Case_Article_Survey",
                    "url": "/services/data/v38.0/wave/datasets/0Fb32000000TVRzCAO"
                }
            ],
            "isFacet": true,
            "isGlobal": false,
            "query": {
                "pigql": "q = load \"Case_Article_Survey\";\r\nq = group q by 'CreatedDate_Hour';\r\nq = foreach q generate 'CreatedDate_Hour' as 'CreatedDate_Hour', count() as 'count';\r\nq = order q by 'CreatedDate_Hour' asc;\r\nq = limit q 2000;",
                "measures": [
                    [
                        "count",
                        "*",
                        "count"
                    ]
                ],
                "action": "computeExpression",
                "parameters": {
                    "source": "CreatedDate_Hour",
                    "mergeWithSource": true,
                    "computedFields": [
                        {
                            "name": "CreatedDate_Hour_adjusted",
                            "type": "Datetime",
                            "format": "MM/dd/yyyy HH:mm:ss",
                            "saqlExpression": "toDate(CreatedDate_Hour  - 8*3600)"
                        }
                    ]
                },
                "measuresMap": {},
                "autoFilter": true,
                "groups": [
                    "CreatedDate_Hour"
                ]
            },
            "selectMode": "single",
            "type": "aggregateflex",
            "useGlobal": false,
            "visualizationParameters": {
                "options": {}
            }
        },

This code is not subtracting 8 hours from CreatedDate_Hour.

1 Answer 1

0

CreatedDate is actually a DateTime field and you've specified a format of MM/dd/yyyy to which you want to add hours. You've omitted the HH:mm:ss needed by a DateTime, particularly since you're going to add or subtract hours to adjust the time zone. Take a look at the toDate functions on page 26 of the document you referenced for more insight on this.

The toDate(CreatedDate_Hour_3 - 8*3600) subtracts 8 hours from CreatedDate_Hour_3. Is that what you want to do? Will all of that data from your SAQL query be in a time zone that's 8 hours different than you want? If not, you'll need to adjust your code even further.

Edit:

In the example you referenced, it takes an existing date CreatedDate_sec_epoch and subtracts 8 hours to create a new date CreateDateNew. The equivalent in your code would require that your dataset have a field named CreatedDate_Hour_3. The error message that you're now receiving would indicate that either the field doesn't exist, or else isn't properly formatted.

I recommend you look at your source data to determine exactly what format it's in and then adjust your code accordingly. That would seem to be what the original error message was likely telling you to begin with, but not with enough specificity to recognize it.

5
  • Yes all of the Created Date data needs to have 8 hours subtracted.
    – Allen Mann
    Commented Jan 24, 2017 at 18:51
  • I made the changes you suggested but now I am seeing Invalid IDTOKEN: CreatedDate_Hour_3
    – Allen Mann
    Commented Jan 24, 2017 at 19:36
  • See my edit. I think there's an issue with your source data.
    – crmprogdev
    Commented Jan 24, 2017 at 20:02
  • See edit. I updated the code to use the CreatedDate_Hour in the computeExpression. No change reflected in the dashboard.
    – Allen Mann
    Commented Jan 24, 2017 at 20:21
  • I suspect that your source data is labeled CreatedDate, which is what you want to replace when your query runs.
    – crmprogdev
    Commented Jan 24, 2017 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .