-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
166 lines (138 loc) · 6.99 KB
/
script.js
File metadata and controls
166 lines (138 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const ssjsTemplate = `
<script runat="server">
Platform.Load("core", "1");
try {
// Set the name of the SOAP object to "{{SOAPAPIName}}".
var soapObject = {{SOAPAPIName}};
// Call the function 'DescribeSoapObject' to retrieve the metadata information for the SOAP object.
var soapMetaData = DescribeSoapObject(soapObject);
// Extract the properties array from the soapMetaData.
var properties = soapMetaData.Results[0].Properties;
// Fetch the properties of the SOAP object that are available for retrieval.
var cols = FetchRetrieveableProperties(properties);
// Call the function 'RetrieveSoapObject' to retrieve data from the SOAP object using the specified filter and columns.
var response = RetrieveSoapObject(soapObject, cols);
// Convert the response object to a string representation and write it to the output.
Write(Stringify(response));
} catch (ex) {
// If an exception occurs during the execution, catch it and write the error messages to the output.
Write(ex.message);
Write(ex.description);
Write(ex.jintException);
}
// Function to describe a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object to describe.
function DescribeSoapObject(soapObjectname) {
// Create a new instance of WSProxy to interact with the SOAP API.
var api = new Script.Util.WSProxy();
// Call the describe method of WSProxy to fetch the metadata information for the SOAP object.
var response = api.describe(soapObjectname);
// Return the response, which contains the metadata information for the SOAP object.
return response;
}
// Function to fetch an array of retrieveable property names from SOAP metadata.
// Parameters:
// - soapMetaData: An array of objects containing metadata information for SOAP properties.
function FetchRetrieveableProperties(soapMetaData) {
// Create an empty array to store the names of retrieveable properties.
var propertiesName = [];
// Iterate through each object in the soapMetaData array.
for (var i in soapMetaData) {
// Extract the 'Name' property from the current object and store it in the propertiesName array.
var name = soapMetaData[i].Name;
var isRetrievable = soapMetaData[i].IsRetrievable;
if (isRetrievable === true) {
propertiesName.push(name);
}
}
// Return the array containing the names of retrieveable properties.
return propertiesName;
}
// Function to create a filter object for data retrieval or processing.
// Parameters:
// - prop: The property name to filter on.
// - operator: The operator used for filtering (e.g., equals, greater than, less than, etc.).
// - value: The value to compare the property against.
function ApplyFilter(prop, operator, value) {
// Create and return a filter object with the specified properties.
return {
Property: prop, // The property name on which the filter is applied.
SimpleOperator: operator, // The operator used for the filter (e.g., 'equals', 'greaterThan', etc.).
Value: value // The value to compare the property against.
};
}
// Function to retrieve data from a SOAP object using WSProxy.
// Parameters:
// - soapObjectname: The name of the SOAP object from which data will be retrieved.
// - cols: An array of column names to retrieve from the SOAP object.
// - filter: A filter to apply when querying the SOAP object (optional).
function RetrieveSoapObject(soapObjectname, cols) {
// Create a new instance of WSProxy to interact with the SOAP object.
var api = new Script.Util.WSProxy();
api.setClientId({
"ID": Platform.Function.AuthenticatedMemberID(),
"UserID": Platform.Function.AuthenticatedEmployeeID()
});
// Call the retrieve method of WSProxy to fetch data from the SOAP object.
var response = api.retrieve(soapObjectname, cols);
// Return the response, which contains the retrieved data from the SOAP object.
return response;
}
</script>
`;
function onApiSelect(apiName) {
document.getElementById('code-editor-container').style.display = 'block';
let codeWithAPIName = ssjsTemplate.replace(/{{SOAPAPIName}}/g, `"${apiName}"`);
document.getElementById('code-editor').textContent = decodeHTML(codeWithAPIName);
Prism.highlightAll();
// Use a small delay to ensure rendering completes before resetting scroll
setTimeout(function () {
const codeEditorPre = document.querySelector('#code-editor-container pre');
codeEditorPre.scrollTop = 0; // Reset scroll position to the top
}, 0);
}
function decodeHTML(html) {
const txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
function copyToClipboard() {
const codeText = document.getElementById("code-editor").textContent;
navigator.clipboard.writeText(codeText)
.then(() => {
const modal = document.getElementById("copyModal");
// Show the modal and then fade it out
modal.classList.add("show");
// After 3 seconds, fade out the modal
setTimeout(() => {
modal.classList.remove("show");
}, 2000); // 2 seconds to keep the modal visible before fading out
})
.catch(err => console.error("Error copying code: ", err));
}
document.addEventListener('DOMContentLoaded', () => {
// Get the first radio button in the soap-api-list
const firstRadioButton = document.querySelector('.soap-api-list input[type="radio"]');
if (firstRadioButton) {
firstRadioButton.checked = true; // Set the first radio button as checked by default
}
// Optional: If you want to trigger any event (e.g., change) after selecting the first item
if (firstRadioButton) {
const changeEvent = new Event('change');
firstRadioButton.dispatchEvent(changeEvent);
}
// You can add more JavaScript logic here for other functionalities if needed
});
document.addEventListener('contextmenu', function(event) {
event.preventDefault();
}, false);
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && (event.key === 'u' || event.key === 'U')) {
event.preventDefault();
}
});
document.querySelector(".theme-toggle-btn").addEventListener("click", () => {
const currentTheme = document.documentElement.dataset.theme || "dark";
document.documentElement.dataset.theme = currentTheme === "dark" ? "light" : "dark";
});