2016-09-06 69 views
0

我已經創建了此用戶界面宏(仍在開發中),並將其包含在用戶界面頁面中,並且沒有任何問題;但是,當我嘗試通過PA儀表板將UI宏包含到動態內容塊中時,它不會呈現任何內容?ServiceNow動態內容塊問題

完整代碼宏(試試看):

<?xml version="1.0" encoding="utf-8" ?> 
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> 

<script language="javascript" src="/scripts/prototype-adapter.jsx" /> 
<script language="javascript" src="/scripts/GlideV2ChartingIncludes.jsx" /> 
    <g:evaluate> 
    var time = []; 
    var newIncidents = []; 
    var resIncidents = []; 
    var incidentsJson = '['; 
    var gr = GlideRecord('sys_trend'); 
    gr.addQuery('name', 'New Incidents'); 
    gr.query(); 
    while(gr.next()){ 

    newIncidents.push(gr.value.toString()); 
    incidentsJson += '{"y": '+parseInt(gr.value.toString(), 10)+', "name": "'+gr.collected+'"}',; 
    } 
    newIncidents = newIncidents.join(','); 
    incidentsJson = incidentsJson.slice(0,-1); 
     incidentsJson += ']'; 
    </g:evaluate> 
<script> 
    var incidentsJson = '${incidentsJson}'; 
    var incidents = "${newIncidents}"; 
    var I = incidents.split(','); 
    for(var i=0; i != I.length; i++) { 
    I[i] = parseInt(I[i], 10); 
    } 

document.observe("dom:loaded", function() { 
    var chart1 = new Highcharts.Chart({ 
    chart: { 
    renderTo: 'newchart', 
    type: 'line' 
    }, 
      title: { 
      text: 'Backlog Growth', 
      x: -20 //center 
     }, 

     xAxis: { 
      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
       'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 
     }, 
     yAxis: { 
      title: { 
       text: 'Growth' 
      }, 
      plotLines: [{ 
       value: 0, 
       width: 1, 
       color: '#808080' 
      }] 
     }, 
     tooltip: { 
      valueSuffix: '#' 
     }, 
     legend: { 
      layout: 'vertical', 
      align: 'right', 
      verticalAlign: 'middle', 
      borderWidth: 0 
     }, 
     series: [{ 
      name: 'Incidents', 
      data: [{"y": 29, "name": "2016-09-04 21:57:21"},{"y": 28, "name": "2016-09-05 21:57:22"}] 
    }, { 
    name: 'Requested Items', 
    data: [{"y": 50, "name": "2016-09-04 21:57:21"},{"y": 25, "name": "2016-09-05 21:57:22"}] 
    }, { 
    name: 'Demands', 
    data: [{"y": 10, "name": "2016-09-04 21:57:21"},{"y": 5, "name": "2016-09-05 21:57:22"}] 

     }] 
    }); 
}); 
</script> 
<div class="container-fluid"> 
<div id="highwrapper" style="width: 500px; height: 400px; position:relative;"> 
    <div id="newchart" style="min-width: 500px; height: 400px; margin: 20; position:absolute;top:0px;left:0px;"></div> 

</div> 
    </div> 
</j:jelly> 

代碼在UI頁面或內容區塊包括:

<?xml version="1.0" encoding="utf-8" ?> 
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> 
    <g:macro_invoke macro="custom_backlog_line_chart"/> 
</j:jelly> 

工作得很好,當我的「實戰」中一個UI頁面,但當我在儀表板中的動態內容塊小部件中使用它時,我會得到空白小部件。

另外如果有人能弄清楚爲什麼我不能將$ {incidentsJson}傳遞給我的系列:data:在我的圖表中,這也會非常有用!現在我正在硬編碼json輸出是什麼來顯示圖表。如果我嘗試將它傳遞給數據:我得到一個空白圖表...

我只是試圖

series: [{ 
      name: 'Incidents', 
      data: incidentsJson 
    }, 

我的jsfiddle測試的Highcharts.com網站,我可以JSON數組分配給var和將它傳遞給系列沒有問題,但在SN中無法做到。

在此先感謝!

########更新

好吧,我發現兩個問題1是一個錯位的逗號。

incidentsJson += '{"y": '+parseInt(gr.value.toString(), 10)+', "name": "'+gr.collected+'"}',; 

我不小心把它放在''之外,所以它應該看起來像這樣。

incidentsJson += '{"y": '+parseInt(gr.value.toString(), 10)+', "name": "'+gr.collected+'"},'; 

第二個問題是將評估變量傳遞給腳本部分不應包含在''中。

var incidentsJson = '${incidentsJson}'; RIGHT var incidentsJson = ${incidentsJson};

接下來我能夠通過incidentsJson的數據系列。

series: [{ 
      name: 'Incidents', 
      data: incidentsJson 
     }, 

這裏是輸出

enter image description here

+0

我能不過來渲染圖,仍然無法傳遞到圖表數據系列 –

+0

你確定你有正確的數據格式的變量? –

+0

嗨yes文檔聲明它可以處理一個對象,字符串或整數。但事實證明,我有一個錯位的逗號和引號。 –

回答

0

好了,所以我發現了兩個問題,1是一個錯位逗號這裏。

incidentsJson += '{"y": '+parseInt(gr.value.toString(), 10)+', "name": "'+gr.collected+'"}',; 

我不小心把它放在''之外,所以它應該看起來像這樣。

incidentsJson += '{"y": '+parseInt(gr.value.toString(), 10)+', "name": "'+gr.collected+'"},'; 

第二個問題是將評估變量傳遞給腳本部分不應包含在''中。

var incidentsJson = '${incidentsJson}'; RIGHT var incidentsJson = ${incidentsJson};

接下來我能夠通過incidentsJson的數據系列。

series: [{ 
      name: 'Incidents', 
      data: incidentsJson 
     }, 

輸出

enter image description here