Skip to content

Instantly share code, notes, and snippets.

@lyatziv
Last active February 27, 2025 16:14
Show Gist options
  • Save lyatziv/d9dfc44ec344113dada9a803265d5524 to your computer and use it in GitHub Desktop.
Save lyatziv/d9dfc44ec344113dada9a803265d5524 to your computer and use it in GitHub Desktop.
See Links to script deployments in the filecabinet using SuiteQl
// ==UserScript==
// @name Get File script deployments
// @namespace http://tampermonkey.net/
// @version 2025-02-25
// @description Print a list of deployments for a script in the file cabinet
// @author Lavi Yatziv
// @match https://*.app.netsuite.com/app/common/media/mediaitem.nl?id=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=netsuite.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
require(["N"], function (N) {
for (var n in N) {
window[n] = N[n];
}
const queryString = (fileId) => `
SELECT
scriptDeployment.scriptid AS script_name,
script.id AS script_id
FROM
scriptDeployment
JOIN script ON
scriptDeployment.script = script.id
JOIN File ON
script.scriptfile = File.id
WHERE
scriptDeployment.isdeployed = 'T'
AND
File.filetype = 'JAVASCRIPT'
AND
File.id = ${fileId}
`;
try {
const cr = currentRecord.get();
const fileId = cr.id;
const queryResult = query.runSuiteQL({ query: queryString(fileId) });
const mappedResults = queryResult.asMappedResults();
const links = [];
const scheme = "https://";
const host = url.resolveDomain({
hostType: url.HostType.APPLICATION,
});
mappedResults.forEach((result) => {
const scriptLink = url.resolveRecord({
recordType: "script",
recordId: result.script_id,
isEditMode: true,
});
const scriptPath = `${scheme}${host}${scriptLink}`;
links.push({Deployment: result.script_name, link:`<a href="${scriptPath}">${scriptLink}</a>`});
});
console.table(links);
const deploymentTableHeadings = `<tr>${Object.keys(links[0]).map(heading => `<th>${heading}</th>`).join('')}</tr>`
const deploymentTableRows = `${links.map(rowObj => `<tr>${Object.values(rowObj).map(cell => `<td>${cell}</td>`).join('')}</tr>`).join('')}`
const deploymentTableMarkup = `<table>${deploymentTableHeadings}${deploymentTableRows}</table>`
const main_form = document.getElementById('main_form');
const linkTable = document.createElement('div');
linkTable.id = 'link_table'
linkTable.style.fontSize = '0.8rem'
linkTable.innerHTML = deploymentTableMarkup
main_form.appendChild(linkTable)
} catch (e) {
console.error(e);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment