cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Referencing variables outside of the default function now fails

thomas_c
Dynatrace Contributor
Dynatrace Contributor

Hi Team,

I just noticed new errors when loading certain code tiles in my dashboard:

 

{
  "error": {
    "code": 540,
    "message": "Execution crashed.",
    "details": {
      "logs": "",
      "type": "UNCAUGHT_EXCEPTION",
      "message": "Uncaught (in promise) ReferenceError: $Scope is not defined",
      "details": {
        "sourceLine": "  if($Scope[0] === \"Tenant\") {",
        "lineNumber": 409,
        "startColumn": 3,
        "stack": "ReferenceError: $Scope is not defined\n    at webApps (file:///script.ts:409:3)\n    at getWeightedScore (file:///script.ts:30:23)\n    at default (file:///script.ts:1010:33)"
      }
    }
  }
}

 

The code didn't change and was working for the past year.

I notice that references to the variable "Scope" only fail when located in functions other than the export default async function().

I didn't notice any change in the public documentation.

Could you help me fix that error please?

4 REPLIES 4

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

Hi @thomas_c 

 

Please create a support ticket via https://one.dynatrace.com/hc/en-us/requests . Tech support will help you with this issue. Please attach the snipped code or the link to the snippet to the ticket.

 

Best,
Sini

thomas_c
Dynatrace Contributor
Dynatrace Contributor

Hi @sinisa_zubic 

I discovered that $variable objects cannot be referenced outside of the export default async function() anymore. So, the issue is fixed by passing such object as argument of other functions.

Thanks

Dynosaure
Frequent Guest

Good morning,
We also encounter the same problem following the last update. Is there a solution. it no longer recognizes the time zone. Thanks for your help

 

import { problemsClient } from "@dynatrace-sdk/client-classic-environment-v2";

export default async function fetchMetricResults() {
let probS = "";
if($OS == "WINDOWS") probS += "entityTags(\"OS:Windows\"),";
else if ($OS == "LINUX") probS += "entityTags(\"OS:Linux\"),";
if($ManagementZone != "ALL") probS += "managementZones(" + $ManagementZone.toString() + "),";

probS += "status(\"open\")";

const total = await problemsClient.getProblems({
from: Date.parse($dt_timeframe_from).toString(),
to: Date.parse($dt_timeframe_to).toString(),
problemSelector: probS,
pageSize: 1
});

const critical = await problemsClient.getProblems({
from: Date.parse($dt_timeframe_from).toString(),
to: Date.parse($dt_timeframe_to).toString(),
problemSelector: "text(\"CRITICAL\")," + probS,
pageSize: 1
});

const warning = await problemsClient.getProblems({
from: Date.parse($dt_timeframe_from).toString(),
to: Date.parse($dt_timeframe_to).toString(),
problemSelector: "text(\"WARNING\")," + probS,
pageSize: 1
});

return " 🔴 " + total.totalCount
}

thomas_c
Dynatrace Contributor
Dynatrace Contributor

Hi @Dynosaure 

As the $dt_timeframe_from and $dt_timeframe_to variables are still used within the export default async function, I wouldn't say it's the same issue/root cause as I described above. And the solution I provided will not solve it.

That's why I believe your situation deserves a whole new thread in the community as it will require a different explanation/solution from Dynatrace R&D teams.

Hope that helps (a tiny bit).

Featured Posts