Skip to content

Commit

Permalink
Add /copycolumn command and fix manifest file for
Browse files Browse the repository at this point in the history
Edge
  • Loading branch information
arnoudkooi committed Dec 8, 2023
1 parent 2ea1de1 commit a4c9ee0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG.md

## 7.1.9.0 (2023-12-08)
Features:
- Added /copycolumn command, in addition to /copycells It will copy all non empty values of the column where a cell is selected.
Fixes / changes:
- Adjust manifest file for Edge to allow servicenowservices.com domain
- Expand the doubleclick area in the headerbar to trigger page reload
- Fix to support the /um unmnadatory command inside Next Experience

## 7.1.8.0 (2023-12-04)
Fixes / changes:
- Show the quick add button on related lists (Discussion #451)
Expand Down
34 changes: 28 additions & 6 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var snuslashcommands = {
"url": "*",
"hint": "Copy Selected Cell Values from List [-s for SysIDs]"
},
"copycolumn": {
"url": "*",
"hint": "Copy All Values from Selected Column [-s for SysIDs]"
},
"debug": {
"url": "*",
"hint": "Open Script Debugger"
Expand Down Expand Up @@ -883,8 +887,8 @@ function snuSlashCommandAddListener() {
}
return;
}
else if (shortcut == "copycells") {
snuCopySelectedCellValues(query);
else if (shortcut == "copycells" || shortcut == "copycolumn") {
snuCopySelectedCellValues(query, shortcut);
snuSlashCommandHide();
return;
}
Expand Down Expand Up @@ -1802,7 +1806,7 @@ function snuDoubleClickToShowFieldOrReload() {
} else {
alert('[SN Utils]\nField Type: ' + glideUIElement.type + '\nField: ' + elm + '\nValue:' + val);
}
} else if (event.target.classList.contains('container-fluid')) {
} else if (event.target.classList.contains('container-fluid') || event.target.classList.contains('navbar_ui_actions')) {
location.reload();
} else if (event.target.classList.contains('breadcrumb_container')) {
//placeholder maybe move breadcrumb doubleclick here
Expand Down Expand Up @@ -3666,9 +3670,9 @@ function snuFillFields(query) {
}
};

function snuCopySelectedCellValues(copySysIDs) {
function snuCopySelectedCellValues(copySysIDs, shortcut = "copycells") {
var hasCopied = false;
var selCells = window.top.document.querySelectorAll('.list_edit_selected_cell');
var selCells = window.top.document.querySelectorAll('.list_edit_selected_cell, .list_edit_cursor_cell');
if (selCells.length > 0) {
doCopy(selCells);
hasCopied = true;
Expand All @@ -3678,7 +3682,7 @@ function snuCopySelectedCellValues(copySysIDs) {
iframes = document.querySelector("[global-navigation-config]").shadowRoot.querySelectorAll("iframe");

Array.from(iframes).forEach(function (frm) {
selCells = frm.contentWindow.document.querySelectorAll('.list_edit_selected_cell');
selCells = frm.contentWindow.document.querySelectorAll('.list_edit_selected_cell, .list_edit_cursor_cell');
if (selCells.length > 0) {
doCopy(selCells, frm);
hasCopied = true;
Expand All @@ -3689,6 +3693,14 @@ function snuCopySelectedCellValues(copySysIDs) {
function doCopy(selCells, frm) {
var str = '';
var wdw = (frm) ? frm.contentWindow : window;

if (shortcut == "copycolumn") {
let firstCell = selCells[0];
let columnIndex = Array.from(firstCell.parentElement.children).indexOf(firstCell);
let rows = firstCell.closest('table').querySelectorAll('tr');
selCells = Array.from(rows).map(row => row.cells[columnIndex]).filter(td => td !== undefined && td.classList.contains('vt') && td.innerText);
}

selCells.forEach(function (cElem) {
if (copySysIDs) {
if (cElem.querySelector('a')) {
Expand Down Expand Up @@ -3941,6 +3953,16 @@ function snuAddBGScriptButton() {
}

function snuSetAllMandatoryFieldsToFalse() {

var iframes = window.top.document.querySelectorAll("iframe");
if (!iframes.length && document.querySelector("[global-navigation-config]")) //try to find iframe in case of polaris
iframes = document.querySelector("[global-navigation-config]").shadowRoot.querySelectorAll("iframe");

iframes.forEach((iframe) => {
if (typeof iframe.contentWindow.unhideFields != 'undefined')
iframe.contentWindow.snuSetAllMandatoryFieldsToFalse();
});

if (typeof g_form != 'undefined' && typeof g_user != 'undefined') {
if (g_user.hasRole('admin')) {
var fields = g_form.getEditableFields();
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "SN Utils",
"description": "Productivity tools for ServiceNow. (Personal work, not affiliated to ServiceNow)",
"author": "Arnoud Kooi / arnoudkooi.com",
"version": "7.1.8.0",
"version": "7.1.9.0",
"manifest_version": 3,
"permissions": [
"activeTab",
Expand Down
3 changes: 2 additions & 1 deletion publish/manifest-edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"js/*"
],
"matches": [
"https://*.service-now.com/*"
"https://*.service-now.com/*",
"https://*.servicenowservices.com/*"
]
}
],
Expand Down

0 comments on commit a4c9ee0

Please sign in to comment.