- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 04:01 AM
Hello, I have the below script which I cannot get to work within a dynamic content widget on a dashboard. Any help with where I'm going wrong is appreciated.
The aim of the script is to compare PA scores against their targets to show the latest score with a color.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 04:58 AM
Encoded Queries: Ensure the encoded queries correctly match your data requirements.
Variable Parsing: Use parseInt to convert string values to integers before comparison.
Jelly Tags: Use <j:if>, <j:set>, <j:choose>, <j:when>, and <j:otherwise> correctly to manage the logic and output.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- Fetch target value -->
<g:evaluate var="jvar_now_GR" object="true">
var now_GR = new GlideRecord("pa_target_values");
now_GR.addEncodedQuery("target=005b21201b660e503f41fe6bd34bcb6b");
now_GR.query();
now_GR;
</g:evaluate>
<j:if test="${jvar_now_GR.next()}">
<j:set var="jvar_target" value="${parseInt(jvar_now_GR.getValue('value'))}"/>
</j:if>
<!-- Fetch today's score -->
<g:evaluate var="jvar_score_today" object="true">
var score = new GlideRecord("pa_scores");
score.addEncodedQuery("indicator=8eeeb5d41b668a50d7f9b886d34bcb08^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
score.orderBy("sys_created_on");
score.query();
score;
</g:evaluate>
<j:if test="${jvar_score_today.next()}">
<j:set var="jvar_score_1" value="${parseInt(jvar_score_today.getValue('value'))}"/>
</j:if>
<!-- Fetch yesterday's score -->
<g:evaluate var="jvar_score_yest" object="true">
var score = new GlideRecord("pa_scores");
score.addEncodedQuery("indicator=8eeeb5d41b668a50d7f9b886d34bcb08^sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
score.orderBy("sys_created_on");
score.query();
score;
</g:evaluate>
<j:if test="${jvar_score_yest.next()}">
<j:set var="jvar_score_2" value="${parseInt(jvar_score_yest.getValue('value'))}"/>
</j:if>
<!-- Determine the color based on the score comparison -->
<j:choose>
<j:when test="${jvar_score_1 > jvar_target && jvar_score_2 > jvar_target}">
<p style="color:red;">${jvar_score_1}</p>
</j:when>
<j:when test="${jvar_score_1 > jvar_target}">
<p style="color:yellow;">${jvar_score_1}</p>
</j:when>
<j:otherwise>
<p style="color:green;">${jvar_score_1}</p>
</j:otherwise>
</j:choose>
</j:jelly>
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 04:58 AM
Encoded Queries: Ensure the encoded queries correctly match your data requirements.
Variable Parsing: Use parseInt to convert string values to integers before comparison.
Jelly Tags: Use <j:if>, <j:set>, <j:choose>, <j:when>, and <j:otherwise> correctly to manage the logic and output.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- Fetch target value -->
<g:evaluate var="jvar_now_GR" object="true">
var now_GR = new GlideRecord("pa_target_values");
now_GR.addEncodedQuery("target=005b21201b660e503f41fe6bd34bcb6b");
now_GR.query();
now_GR;
</g:evaluate>
<j:if test="${jvar_now_GR.next()}">
<j:set var="jvar_target" value="${parseInt(jvar_now_GR.getValue('value'))}"/>
</j:if>
<!-- Fetch today's score -->
<g:evaluate var="jvar_score_today" object="true">
var score = new GlideRecord("pa_scores");
score.addEncodedQuery("indicator=8eeeb5d41b668a50d7f9b886d34bcb08^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
score.orderBy("sys_created_on");
score.query();
score;
</g:evaluate>
<j:if test="${jvar_score_today.next()}">
<j:set var="jvar_score_1" value="${parseInt(jvar_score_today.getValue('value'))}"/>
</j:if>
<!-- Fetch yesterday's score -->
<g:evaluate var="jvar_score_yest" object="true">
var score = new GlideRecord("pa_scores");
score.addEncodedQuery("indicator=8eeeb5d41b668a50d7f9b886d34bcb08^sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()");
score.orderBy("sys_created_on");
score.query();
score;
</g:evaluate>
<j:if test="${jvar_score_yest.next()}">
<j:set var="jvar_score_2" value="${parseInt(jvar_score_yest.getValue('value'))}"/>
</j:if>
<!-- Determine the color based on the score comparison -->
<j:choose>
<j:when test="${jvar_score_1 > jvar_target && jvar_score_2 > jvar_target}">
<p style="color:red;">${jvar_score_1}</p>
</j:when>
<j:when test="${jvar_score_1 > jvar_target}">
<p style="color:yellow;">${jvar_score_1}</p>
</j:when>
<j:otherwise>
<p style="color:green;">${jvar_score_1}</p>
</j:otherwise>
</j:choose>
</j:jelly>
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark