- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 10:36 PM
Hi , I have a requirement to return a table in script include :
currently it is giving the table content but not printing in table format
COde :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 12:51 AM
Hello @avinashdubey103 ,
Don't know but somehow my reply got deleted, anyways please give a try to the script below and let me know how it works for you.
var displayRitmTables = Class.create();
displayRitmTables.prototype = {
generateEmailContent: function (current) {
var emailContent = "<br> General Information : <br>";
var table = current.getTableName();
var count = 0;
if (table == 'sysapproval_approver') {
count = 1;
} else {
for (vars in current.variable_pool) {
if (current.variable_pool[vars].item_option_new_set === 'vs_amdocs_requestor') {
continue;
}
count++;
}
}
if (count > 0) {
var mvalue = '';
var list = [];
var display = [];
emailContent += '<br><table border="1" style="font-family: Arial;">';
if (table == 'sc_req_item' || table == 'sc_task' || table == 'sysapproval_approver') {
var listOfVariables = gs.getProperty('variables_exclude');
var variablesArray = listOfVariables.split(',');
var itemVars = new GlideRecord('sc_item_option_mtom');
if (table == 'sc_req_item') {
itemVars.addQuery('request_item', current.sys_id);
} else if (table == 'sc_task') {
itemVars.addQuery('request_item', current.request_item.sys_id);
} else if (table == 'sysapproval_approver') {
itemVars.addQuery('request_item', current.sysapproval.sys_id);
}
itemVars.addEncodedQuery("sc_item_option.item_option_newNOT IN" + variablesArray.join(','));
itemVars.addQuery('sc_item_option.item_option_new.type', 'NOT IN', [11, 19, 20, 24]);
itemVars.orderBy('sc_item_option.order');
itemVars.query();
while (itemVars.next()) {
emailContent += "<tr>";
emailContent += "<td>" + itemVars.sc_item_option.item_option_new.question_text + "</td>";
mvalue = itemVars.sc_item_option.value;
if (itemVars.sc_item_option.item_option_new.type == '8') {
mvalue = this.getDisplayValueFromReference(itemVars.sc_item_option.item_option_new.reference, mvalue);
} else if (itemVars.sc_item_option.item_option_new.type == '21') {
list = itemVars.sc_item_option.value.split(',');
for (var i = 0; i < list.length; i++) {
display.push(this.getDisplayValueFromReference(itemVars.sc_item_option.item_option_new.list_table, list[i]));
}
mvalue = display.join(', ');
} else if (itemVars.sc_item_option.item_option_new.type == '5') {
mvalue = this.getDisplayValueFromChoice(itemVars.sc_item_option.item_option_new, mvalue);
}
emailContent += "<td>" + gs.htmlEscape(mvalue) + "</td>";
emailContent += "</tr>";
}
}
emailContent += "</table>";
}
return emailContent;
},
getDisplayValueFromReference: function (tableName, sysId) {
var grRefTable = new GlideRecord(tableName);
if (grRefTable.get(sysId)) {
return grRefTable.getDisplayValue();
}
return sysId;
},
getDisplayValueFromChoice: function (itemOption, value) {
var grQuestion = new GlideRecord('question_choice');
grQuestion.addQuery('question', itemOption);
grQuestion.addQuery('value', value.toString());
if (grQuestion.query() && grQuestion.next()) {
return grQuestion.getValue('text');
}
return value;
},
type: 'displayRitmTables'
};
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 12:43 AM
@Aniket Chavan
i am not able to see your suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 12:51 AM
Hello @avinashdubey103 ,
Don't know but somehow my reply got deleted, anyways please give a try to the script below and let me know how it works for you.
var displayRitmTables = Class.create();
displayRitmTables.prototype = {
generateEmailContent: function (current) {
var emailContent = "<br> General Information : <br>";
var table = current.getTableName();
var count = 0;
if (table == 'sysapproval_approver') {
count = 1;
} else {
for (vars in current.variable_pool) {
if (current.variable_pool[vars].item_option_new_set === 'vs_amdocs_requestor') {
continue;
}
count++;
}
}
if (count > 0) {
var mvalue = '';
var list = [];
var display = [];
emailContent += '<br><table border="1" style="font-family: Arial;">';
if (table == 'sc_req_item' || table == 'sc_task' || table == 'sysapproval_approver') {
var listOfVariables = gs.getProperty('variables_exclude');
var variablesArray = listOfVariables.split(',');
var itemVars = new GlideRecord('sc_item_option_mtom');
if (table == 'sc_req_item') {
itemVars.addQuery('request_item', current.sys_id);
} else if (table == 'sc_task') {
itemVars.addQuery('request_item', current.request_item.sys_id);
} else if (table == 'sysapproval_approver') {
itemVars.addQuery('request_item', current.sysapproval.sys_id);
}
itemVars.addEncodedQuery("sc_item_option.item_option_newNOT IN" + variablesArray.join(','));
itemVars.addQuery('sc_item_option.item_option_new.type', 'NOT IN', [11, 19, 20, 24]);
itemVars.orderBy('sc_item_option.order');
itemVars.query();
while (itemVars.next()) {
emailContent += "<tr>";
emailContent += "<td>" + itemVars.sc_item_option.item_option_new.question_text + "</td>";
mvalue = itemVars.sc_item_option.value;
if (itemVars.sc_item_option.item_option_new.type == '8') {
mvalue = this.getDisplayValueFromReference(itemVars.sc_item_option.item_option_new.reference, mvalue);
} else if (itemVars.sc_item_option.item_option_new.type == '21') {
list = itemVars.sc_item_option.value.split(',');
for (var i = 0; i < list.length; i++) {
display.push(this.getDisplayValueFromReference(itemVars.sc_item_option.item_option_new.list_table, list[i]));
}
mvalue = display.join(', ');
} else if (itemVars.sc_item_option.item_option_new.type == '5') {
mvalue = this.getDisplayValueFromChoice(itemVars.sc_item_option.item_option_new, mvalue);
}
emailContent += "<td>" + gs.htmlEscape(mvalue) + "</td>";
emailContent += "</tr>";
}
}
emailContent += "</table>";
}
return emailContent;
},
getDisplayValueFromReference: function (tableName, sysId) {
var grRefTable = new GlideRecord(tableName);
if (grRefTable.get(sysId)) {
return grRefTable.getDisplayValue();
}
return sysId;
},
getDisplayValueFromChoice: function (itemOption, value) {
var grQuestion = new GlideRecord('question_choice');
grQuestion.addQuery('question', itemOption);
grQuestion.addQuery('value', value.toString());
if (grQuestion.query() && grQuestion.next()) {
return grQuestion.getValue('text');
}
return value;
},
type: 'displayRitmTables'
};
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 12:52 AM
@Aniket Chavan Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 02:54 AM
Hello @avinashdubey103 ,
Glad I could assist! If there's anything else you need help with in the future, don't hesitate to ask.
Have a great day!