- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2021 07:21 AM
Hi,all
I would like to run the attached script in a job schedule.
However, I get the following error message and cannot run it.
In particular, the error message "sysauto_script.doGlideTabs2 findTabIndexByID could not find section_tab.6ac0938cc0a8000601867d03033a59bd" seems to be a problem. I'm assuming that the sysid shown here is for sys_attachment, but it's not the id I want to get.
How can I run this script without getting an error?
A summary of the script is also provided.
◆A summary of the script
Check the contents of the CSV file attached to the table and insert a record in any field.
◆Error Message=======================================================================
=========================================================
// 添付ファイルTableからCSVデータを抽出する
function getCsv(grAtt) {
var gsAttachment = new GlideSysAttachment();
var byteData = gsAttachment.getBytes(grAtt);
var csvStr;
var parser = new sn_impex.CSVParser();
var headers;
var csvObj;
var csvList = [];
var delimiter = ',';
var quoteCharacter = '"';
if (!byteData) return null;
csvStr = '' + Packages.java.lang.String(byteData, 'UTF-8');// 'UTF-8' or 'MS932' (JavaのSJIS)
if (!csvStr) return null;
csvLine = csvStr.match(/[^\r\n]+/g);
if (!csvLine) return null;
headers = parser.parseLineToArray(csvLine[0], delimiter, quoteCharacter); //
if (!headers) return null;
for (var i = 1; i < csvLine.length; i++) {
csvObj = parser.parseLineToObject(csvLine[i], headers, delimiter, quoteCharacter);
csvList.push(csvObj);
}
return csvList;
}
//var grAtt;32行目にvar追加したためコメントアウト
var csvList;
// インシデントTableから今日一日に作成されたインシデントを検索して添付ファイルがあるなら情報を取得する
var grInc = new GlideRecord('incident');
gs.info('gs.endOfYesterday()=' + gs.endOfYesterday());
grInc.query();
while (grInc.next()) {
var grAtt = new GlideRecord('sys_attachment');
grAtt.addQuery('table_name', 'incident'); //inportst用sysidに変更
grAtt.addQuery('table_sys_id', grInc.getUniqueValue());
grAtt.query();
//ひとつの添付ファイルのみ処理します。複数処理しないのでwhileに変更不要。
while (grAtt.next()) {
if(grAtt.table_sys_id == grInc.getUniqueValue())
{
csvList = getCsv(grAtt);
if (csvList) {
grInc.comments.setJournalEntry('CSV Data ' + JSON.stringify(csvList, null, 2)); //CSVファイルをJSON形式へ変換する処理
if (grInc.update()) {
gs.info(grInc.number + ' update'); //
}
}
break;
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 08:21 AM
Did the entire script not copy? You seem to be missing to end brackets "}" at the bottom of your script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 08:21 AM
Did the entire script not copy? You seem to be missing to end brackets "}" at the bottom of your script.