gpt4 book ai didi

javascript - 如何在servicenow中从javascript访问果冻变量

转载 作者:行者123 更新时间:2023-11-29 23:54:26 26 4
gpt4 key购买 nike

我对 SNOW 有以下要求

我正在尝试通过 gelly 脚本在 UI 页面上生成一组 say 事件记录,并尝试在每条记录的列上显示从记录创建日期开始耗时。我在果冻上使用 while 循环,但它只为第一条记录打印值。其余记录不打印新列值。

我想在 jelly 上有一个变量并从 JS 访问。因为这里的 demo/demo1 是静态的,它们每次都会被覆盖,我只获得一条记录的值(value)。

PFB UI页面脚本:

还有 PFA 屏幕截图。 Screenshot

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_inc">
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('priority',1);
inc.setCategory('homepage');
inc.query();
</g2:evaluate>
<table border="0" cellspacing="2" cellpadding="0" width="100%">
<j2:while test="$[inc.next()]">
<j2:set var="jvar_inc_link" value="incident.do?sys_id=$[inc.sys_id]"/>
<j2:set var="jvar_inc_list_link" value="incident_list.do?sysparm_query=active=true"/>
<tr>
<td>
<a href="$[jvar_inc_link]">
<span style="padding-right:10px;"><IMG SRC="images/icons/incidents.gifx"/></span>
</a>
<a href="$[jvar_inc_link]" class="linked" style="padding-right:10px;">$[inc.number]</a>
</td>
<td>$[inc.short_description]</td>
<td>
<p id="demo1">$[inc.sys_created_on]</p>
</td>
<td>
<p id="demo"></p>
<script>
var myVar = setInterval(myTimer ,1000);
function myTimer() {
var d2 = new Date(document.getElementById("demo1").innerHTML);
var d = new Date();

var d11 = d.getTime();
var d22 = d2.getTime();

var time = (d11 - d22)/1000;

var min = Math.floor(time / 60);
var sec = time - min * 60;
var hh = Math.floor(min / 60);
min = min - hh * 60;
var day = Math.floor(hh / 24);
hh = hh - day * 24;


document.getElementById("demo").innerHTML = day+' : '+hh+' : '+min+' : '+Math.floor(sec);
}

</script>
</td>
</tr>
</j2:while>
<tr>
<td align="center" colspan="2"><a href="$[jvar_inc_list_link]" class="linked">${gs.getMessage("View all active Incidents")}</a></td>
</tr>
</table>
</j:jelly>

最佳答案

试试下面的代码:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_inc">
var inc = new GlideRecord('incident');
inc.addActiveQuery();
inc.addQuery('priority',1);
inc.setCategory('homepage');
inc.query();
</g2:evaluate>
<table border="0" cellspacing="2" cellpadding="0" width="100%">
<script>
var i = 1;
var randomId;
</script>
<j2:while test="$[inc.next()]">
<j2:set var="jvar_inc_link" value="incident.do?sys_id=$[inc.sys_id]"/>
<j2:set var="jvar_inc_list_link" value="incident_list.do?sysparm_query=active=true"/>
<tr>
<td>
<a href="$[jvar_inc_link]">
<span style="padding-right:10px;"><IMG SRC="images/icons/incidents.gifx"/></span>
</a>
<a href="$[jvar_inc_link]" class="linked" style="padding-right:10px;">$[inc.number]</a>
</td>
<td>$[inc.short_description]</td>
<td>
<script>
document.write('<p id="demos'+i+'">$[inc.sys_created_on]</p>');
</script>
</td>
<td>
<script>
document.write('<p id="demo'+i+'" ></p>');
</script>

<script>

//var myVar = setInterval(myTimer ,1000);
myTimer();
function myTimer() {

var d2 = new Date(document.getElementById("demos"+i).innerHTML);
var d = new Date();

var d11 = d.getTime();
var d22 = d2.getTime();

var time = (d11 - d22)/1000;

var min = Math.floor(time / 60);
var sec = time - min * 60;
var hh = Math.floor(min / 60);
min = min - hh * 60;
var day = Math.floor(hh / 24);
hh = hh - day * 24;

randomId = "demo"+i;
console.log(randomId);
document.getElementById(randomId).innerHTML = day+' : '+hh+' : '+min+' : '+Math.floor(sec);
}
i++;
</script>
</td>
</tr>
</j2:while>
<tr>
<td align="center" colspan="2"><a href="$[jvar_inc_list_link]" class="linked">${gs.getMessage("View all active Incidents")}</a></td>
</tr>
</table>
</j:jelly>

关于javascript - 如何在servicenow中从javascript访问果冻变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com