Hi,
I am in multi tenant cloud environment.
And I am trying to find a way for calling Javascript function directly from FromScript.
I have defined User Control Component with this code:
<!DOCTYPE html>
<html>
<head>
<!-- Must set compatibility to IE9 or greater -->
<meta http-equiv="X-UA-Compatible" content="IE=9">
<!-- include the mongoose UserControl.js library -->
<!-- NOTE: MAKE SURE TO MAKE THE src PATH RELATIVE TO THIS FILE -->
<script type="text/javascript" src="../../$app/scripts/UserControl.js"></script>
<script src="https://code.jquery.com/jquery-3.6.4.js"></script>
<script type="text/javascript">
const DownloadFce = {
getVar: function (varName) {
return new Promise((resolve, reject) => {
WSForm.getVarValue(varName, function (value) {
console.log("Value in callback: " + value);
if (value) {
resolve(value);
} else {
reject("no value");
}
});
});
},
};
</script>
<style>
@import url ('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Koulen&family=Lato&family=Nunito&family=Playfair+Display:ital@1 &family=Prata&family=Raleway:ital,wght@1 ,100&family=Roboto&family=Roboto+Condensed&family=Teko&display=swap');
.btn {
font-family: Roboto, Arial, sans-serif;
font-weight: 700;
font-size: 13px;
line-height: 1;
color: #ffffff;
background-color: #1976d2;
border: none;
border-radius: 10px;
min-width: 120px;
height: 32px;
padding: 0 18px;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
</style>
</head>
<body style="font-family:Arial,Helvetica;font-size:12px">
<button class="btn" id="btDownload" onclick="DownloadClick()">Download</button>
<script>
function encodeWindows1250(text) {
const map = {
'€': 0x80, '‚': 0x82, '„': 0x84, '…': 0x85, '†': 0x86, '‡': 0x87, '‰': 0x89,
'Š': 0x8A, '‹': 0x8B, 'Ś': 0x8C, 'Ť': 0x8D, 'Ž': 0x8E, 'Ź': 0x8F,
'‘': 0x91, '’': 0x92, '“': 0x93, '”': 0x94, '•': 0x95, '–': 0x96, '—': 0x97,
'™': 0x99, 'š': 0x9A, '›': 0x9B, 'ś': 0x9C, 'ť': 0x9D, 'ž': 0x9E, 'ź': 0x9F,
'ˇ': 0xA1, '˘': 0xA2, 'Ł': 0xA3, 'Ą': 0xA5, 'Ş': 0xAA, '«': 0xAB, 'Ż': 0xAF,
'°': 0xB0, '±': 0xB1, '˛': 0xB2, 'ł': 0xB3, '´': 0xB4, 'µ': 0xB5, '¶': 0xB6,
'·': 0xB7, '¸': 0xB8, 'ą': 0xB9, 'ş': 0xBA, '»': 0xBB, 'Ľ': 0xBC, '˝': 0xBD,
'ľ': 0xBE, 'ż': 0xBF,
'Ŕ': 0xC0, 'Á': 0xC1, 'Â': 0xC2, 'Ă': 0xC3, 'Ä': 0xC4, 'Ĺ': 0xC5, 'Ć': 0xC6,
'Ç': 0xC7, 'Č': 0xC8, 'É': 0xC9, 'Ę': 0xCA, 'Ë': 0xCB, 'Ě': 0xCC, 'Í': 0xCD,
'Î': 0xCE, 'Ď': 0xCF, 'Đ': 0xD0, 'Ń': 0xD1, 'Ň': 0xD2, 'Ó': 0xD3, 'Ô': 0xD4,
'Ő': 0xD5, 'Ö': 0xD6, '×': 0xD7, 'Ř': 0xD8, 'Ů': 0xD9, 'Ú': 0xDA, 'Ű': 0xDB,
'Ü': 0xDC, 'Ý': 0xDD, 'Ţ': 0xDE, 'ß': 0xDF,
'ŕ': 0xE0, 'á': 0xE1, 'â': 0xE2, 'ă': 0xE3, 'ä': 0xE4, 'ĺ': 0xE5, 'ć': 0xE6,
'ç': 0xE7, 'č': 0xE8, 'é': 0xE9, 'ę': 0xEA, 'ë': 0xEB, 'ě': 0xEC, 'í': 0xED,
'î': 0xEE, 'ď': 0xEF, 'đ': 0xF0, 'ń': 0xF1, 'ň': 0xF2, 'ó': 0xF3, 'ô': 0xF4,
'ő': 0xF5, 'ö': 0xF6, '÷': 0xF7, 'ř': 0xF8, 'ů': 0xF9, 'ú': 0xFA, 'ű': 0xFB,
'ü': 0xFC, 'ý': 0xFD, 'ţ': 0xFE, '˙': 0xFF
};
const bytes = [];
for (let i = 0; i < text.length; i++) {
const ch = text[i];
const code = text.charCodeAt(i);
if (code <= 0x7F) {
bytes.push(code);
} else if (map[ch] !== undefined) {
bytes.push(map[ch]);
} else if (code >= 0xA0 && code <= 0xFF) {
bytes.push(code);
} else {
bytes.push(0x3F);
}
}
return new Uint8Array(bytes);
}
async function DownloadClick() {
let filename = await DownloadFce.getVar("varFilename");
let fileContent = await DownloadFce.getVar("varFileContent");
const bytes = encodeWindows1250(fileContent);
const blob = new Blob([bytes], { type: 'text/plain;charset=windows-1250' });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, filename);
return;
}
const url = URL.createObjectURL(blob);
const element = document.createElement('a');
element.href = url;
element.download = filename;
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
URL.revokeObjectURL(url);
}
</script>
</body>
</html>
It is creating Download button, thru which user can download file. File content is passed from Form Variable. And also here is done converting to Windows-1250 code page.
But is it possible to call this DownloadClick function directly from FormScript?
On docs.infor.com I found this, and there is something about PostUserControlMessage, but it is not explained further: