Created:
Dec 2, 2023 11:44 AM
| Last Modified: Jun 16, 2024 1:24 PM(1428 views)
For Columns and Objects like Reports, there exists a command
obj << Get Data Table();
to get a reference to the respective data table.
Is there a similar function for Table Scripts? something like
This Data Table()
some lazy implementations which could lead to issues:
reference the data table by its name. Data Table ("my table") << new column("test") this works till there is a conflict with another data table with the same name and " 2" is added automatically to the table name.
use mydt = current data table() to generate a reference to the data table This works fine if I run the script from the table itself. To have the chance to click on the play button, one has to select the data table. Therefore, it will be the current one. good. But when I trigger the Table Script via dt << run sricpt ("myscript"), another data table could be the current one. edit #1: @jthi's example below suggests, that this statement is not correct: When you trigger a table script, the table with the table script gets the current data table. so: no issues. edit #2: ... but it seems that "gets the current data table" doesn't happen immediately. so: under some circumstances there could be some issues (see below)
I believe that a script in a data table implicitly sends messages to the data table that encloses the script. So explicitly referring to the data table using "current data table" is unnecessary.
If you run a script inside of a data table from out side of the data table, you must obtain the handle of the data table first, such that you can send Run Script("script name") to the data table. The data table can be the current or not, which does not matter.
So, I guess that the answer is that there is no need to use anything, in a script, to refer to the data table that encloses the script. Remove "dt = current data table()" from your script and see how it goes. I guess there are some other reasons why you need that line, but maybe there is a different solution to address that problem.
I believe that a script in a data table implicitly sends messages to the data table that encloses the script. So explicitly referring to the data table using "current data table" is unnecessary.
If you run a script inside of a data table from out side of the data table, you must obtain the handle of the data table first, such that you can send Run Script("script name") to the data table. The data table can be the current or not, which does not matter.
So, I guess that the answer is that there is no need to use anything, in a script, to refer to the data table that encloses the script. Remove "dt = current data table()" from your script and see how it goes. I guess there are some other reasons why you need that line, but maybe there is a different solution to address that problem.
dt = current data table() in the table script: This works fine if I run the script from the table itself. To have the chance to click on the play button, one has to select the data table. Therefore, it will be the current one. good. But when I trigger the Table Script via JSL, another data table could be the current one.
Have you verified this to be the case if you run it via JSL? If I remember correctly I have been running some of my more complicated table scripts just fine through JSL, without needing to worry about correcting the current data table (I might remember wrong though).
Names Default To Here(1);
dt3 = New Table("table with script",
Add Rows(2),
Compress File When Saved(1),
New Script(
"test", JSL Quote(Local Here(
dt = Current Data Table();
dt << Graph Builder(
Size(528, 454),
Show Control Panel(0),
Variables(X(:Column 1), Y(:Column 2)),
Elements(Points(X, Y, Legend(3)), Smoother(X, Y, Legend(4)))
);
show(dt);
);
) ,
As String(1)
),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2])),
New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([2, 3]))
);
dt2 = New Table("current table",
Add Rows(0),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("Column 2", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
Current Data Table(dt2);
Wait(1);
Show(Current Data Table());
dt3 << Run Script("test");
Show(Current Data Table());
Created:
Dec 3, 2023 09:15 AM
| Last Modified: Jun 16, 2024 12:58 PM(1367 views)
| Posted in reply to message from jthi 12-03-2023
Looks convincing
So, when running a table script, the current data table is automatically mapped to the table with the script. So, this is the reason why a script in a data table [...] sends messages to the data table that encloses the script.
Created:
Jun 16, 2024 11:46 AM
| Last Modified: Jun 16, 2024 1:26 PM(635 views)
| Posted in reply to message from hogi 12-03-2023
Hi,
I could replicate my error from 2023 and have new findings:
The problem:
a jsl script triggers dt << run script(myScript)
myscript starts with mydt = current data table();
my original assumption: when I trigger the Table Script via JSL, another data table could be the current one. seems to hold for some cases - today I could generate such a case where
mydt = current data table();
mydt << new column ("test1"); // was sent to the wrong data table
new column("test2"); // was sent to THIS DATA TABLE (fits to Peng Liu's post)
So: If you plan to run a Table script via dt << run script(myScript)
and need a reference to ThisDataTable, add wait(0) to be on the safe side:
wait(0); // !!!!
thisDataTable = current data table();
similar findings, but with slightly different context : run table script
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "This post originally written in lilicon-trans-text has been computer translated for you. When you reply, it will also be translated back to lilicon-trans-text.".replace(/lilicon-trans-text/g, tr_obj[0].title);
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "This message was translated for your convenience!";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("src", "/html/assets/lingoTrFlag.PNG");
tr_fTag.style.marginRight = "5px";
tr_fTag.style.height = "14px";
tr_para.appendChild(tr_fTag);
var tr_textNode = document.createTextNode(tr_text);
tr_para.appendChild(tr_textNode);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelector(".lia-quilt-tkb-message").appendChild(tr_para);
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelector(".lia-quilt-tkb-reply-message").insertBefore(tr_para,rootElement.querySelector(".lia-quilt-row.lia-quilt-row-footer"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message").appendChild(tr_para);
}else if(rootElement.querySelector(".lia-quilt-column-alley-left")){
rootElement.querySelector(".lia-quilt-column-alley-left").appendChild(tr_para);
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '705074' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = " + "'lingo-body-" + value + "'" + "]";
lingoRSExp = "//lingo-sub[@id = " + "'lingo-sub-" + value + "'" + "]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < lingoRSXML.snapshotLength; i++) {
/* Replace Reply/Comment subject with transalted subject */
var newSub = lingoRSXML.snapshotItem(i);
/*** START : extracting subject from source if selected language and source language is same **/
var sub_L = "";
if (newSub.getAttribute("slang").toLowerCase() == code_l.toLowerCase()) {
if (value == '705074') {
sub_L = decodeURIComponent($scope.sourceContent[value].subject);
}
else{
sub_L = decodeURIComponent($scope.sourceContent[value].subject);
}
} else {
sub_L = newSub.innerHTML;
}
/*** End : extracting subject from source if selected language and source language is same **/
/* This code is placed to remove the extra meta tag adding in the UI*/
try{
sub_L = sub_L.replace('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />','');
}
catch(e){
}
// if($scope.viewTrContentOnly || (newSub.getAttribute("slang").toLowerCase() != code_l.toLowerCase())) {
if ($scope.viewTrContentOnly) {
if ("ForumTopicPage" == "IdeaPage") {
if (value == '705074') {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
document.querySelector('.MessageSubject .lia-message-subject').innerHTML = sub_L;
}
}
}
if ("ForumTopicPage" == "TkbArticlePage") {
if (value == '705074') {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
var subTkbElement = document.querySelector('.lia-thread-subject');
if(subTkbElement){
document.querySelector('.lia-thread-subject').innerHTML = sub_L;
}
}
}
}
else if ("ForumTopicPage" == "BlogArticlePage") {
if (value == '705074') {
try {
if((sub_L != "") && (sub_L!= undefined) && (sub_L != "undefined")){
var subElement = rootElement.querySelector('.lia-blog-article-page-article-subject');
if(subElement) {
subElement.innerText = sub_L;
}
}
} catch (e) {
}
/* var subElement = rootElement.querySelectorAll('.lia-blog-article-page-article-subject');
for (var subI = 0; subI < subElement.length; subI++) {
if((sub_L != "") && (sub_L!= undefined) && (sub_L != "undefined")){
subElement[subI].innerHTML = sub_L;
}
} */
}
else {
try {
// rootElement.querySelectorAll('.lia-blog-article-page-article-subject').innerHTML= sub_L;
/** var subElement = rootElement.querySelectorAll('.lia-blog-article-page-article-subject');
for (var j = 0; j < subElement.length; j++) {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
subElement[j].innerHTML = sub_L;
}
} **/
} catch (e) {
}
}
}
else {
if (value == '705074') {
try{
/* Start: This code is written by iTalent as part of iTrack LILICON - 98 */
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
if(document.querySelectorAll('.lia-quilt-forum-topic-page').length > 0){
if(rootElement.querySelector('div.lia-message-subject').querySelector('h5')){
rootElement.querySelector('div.lia-message-subject').querySelector('h5').innerText = decodeURIComponent(sub_L);
} else {
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
} else {
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
}
/* End: This code is written by iTalent as part of iTrack LILICON - 98 */
}
catch(e){
console.log("subject not available for second time. error details: " + e);
}
} else {
try {
/* Start: This code is written by iTalent as part of LILICON - 98 reported by Ian */
if ("ForumTopicPage" == "IdeaPage") {
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
document.querySelector('.lia-js-data-messageUid-'+ value).querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
}
}
else{
if( (sub_L != "") && (sub_L != undefined) && (sub_L != "undefined") ){
rootElement.querySelector('.MessageSubject .lia-message-subject').innerText = sub_L;
/* End: This code is written as part of LILICON - 98 reported by Ian */
}
}
} catch (e) {
console.log("Reply subject not available. error details: " + e);
}
}
}
// Label translation
var labelEle = document.querySelector("#labelsForMessage");
if (!labelEle) {
labelEle = document.querySelector(".LabelsList");
}
if (labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
/* try{
for(var j=0;j,';
}
trLabelsHtml = trLabelsHtml+'