Open pivot
Table_1.openNavigationPanel();
SAP Analytics Cloud (SAC) में table widget के navigation panel को खोलने के लिए SAC scripting command Table_1.openNavigationPanel(); का उपयोग किया जाता है। navigation panel users को application को edit किए बिना dimensions, measures और filters जोड़कर या हटाकर table को interactive रूप से modify करने की अनुमति देता है। यह सुविधा users को Excel में pivot table को customize करने के similar, data को अधिक आसानी से explore करने में मदद करती है। जब यह function execute होता है, तो panel table के side दिखाई देता है, जिससे users को data के display पर control मिलता है। यह end users को self-service data exploration तक quick access प्रदान करने के लिए एक उपयोगी scripting method है।
Open hyperlink from each cell in table:
//get selection
var selections = Table_1.getSelections()[0];
console.log(selections);
console.log(selections["Name"]);
console.log(selections["Dashboard_Link"]);
//if contains link then open
if (selections["Dashboard_Link"].startsWith("http"))
{
NavigationUtils.openUrl(selections["Dashboard_Link"]);
}
यह SAC scripting code Table_1 से selected row प्राप्त करता है और उस row के data के आधार पर एक action करता है। सबसे पहले, यह getSelections()[0] का उपयोग करके selected item को प्राप्त करता है और उसे selection variable में store करता है। फिर यह "Name" और "Dashboard_Link" columns के values को console में log करता है। इसके बाद, यह जाँचता है कि क्या "Dashboard_Link" column का value "http" से शुरू होता है, जिसका अर्थ है कि यह एक valid web link है। यदि सही है, तो यह link को एक नए browser tab में खोलने के लिए NavigationUtils.openUrl() का उपयोग करता है। इससे users सीधे table से dashboard या report खोल सकते हैं।
Update comment table or widget:
// ****************** Get variables from main table **************************
Application.showBusyIndicator("Loading data...");
//get Fiscal Year from prompt
var p1=Table_Order.getDataSource().getVariableValues("V_FPER")[0];
// console.log(p1);
switch (p1.type) {
case VariableValueType.Single:
var singleValue = cast(Type.SingleVariableValue, p1);
Text_6.applyText(singleValue.value);
var cy=Text_6.getPlainText();
var yy=(cy.substring(0,4));
var mm=(cy.substring(5,7));
break;
case VariableValueType.Multiple:
var multiValue = cast(Type.MultipleVariableValue, p1);
console.log(multiValue.values); // can access the 'values' property now
break;
case VariableValueType.Range:
var rangeValue = cast(Type.RangeVariableValue, p1);
console.log("from");
console.log(rangeValue.from); // can access the 'from' property now
console.log("to");
console.log(rangeValue.to); // can access the 'to' property now
break;
default:
break;
}
console.log("month: " + mm);
console.log("year: " + yy);
//remove 0 from month
if(mm==="01"){
mm="1";
}else if(mm==="02"){
mm="2";
}else if(mm==="03"){
mm="3";
}else if(mm==="04"){
mm="4";
}else if(mm==="05"){
mm="5";
}else if(mm==="06"){
mm="6";
}else if(mm==="07"){
mm="7";
}else if(mm==="08"){
mm="8";
}else if(mm==="09"){
mm="9";
}else if(mm==="10"){
mm="10";
}else if(mm==="11"){
mm="11";
}else if(mm==="12"){
mm="12";
}
//prefix 0 in quarter
if(mm==="1" || mm==="2" || mm==="3"){
var qtr="01"; // quarter
var mnth2="3"; //last month of quarter
}else if(mm===
"4" || mm==="5" || mm==="6"){
qtr="02"; // quarter
mnth2="6"; //last month of quarter
}else if(mm==="7" || mm==="8" || mm==="9"){
qtr="03"; // quarter
mnth2="9"; //last month of quarter
}else if(mm==="10" || mm==="11" || mm==="12"){
qtr="04"; // quarter
mnth2="12"; //last month of quarter
}
console.log("qtr month: " + mnth2);
// ******************** update comment table ***************************
Table_29.getDataSource().setDimensionFilter("Quarter","202502");
Table_29.getDataSource().setDimensionFilter("Period","6");
// ******************** update comment widget**************************
CommentWidget_1.getCommentingDataSource().setDimensionFilter("Quarter",yy+qtr);
CommentWidget_1.getCommentingDataSource().setDimensionFilter("Period",mnth2);
Application.hideBusyIndicator();
यह SAC scripting code Table_Order से fiscal period (V_FPER) variable को पढ़ता है और उससे year और month निकालता है। यह months से सभी शुरुआती शून्य हटा देता है और फिर quarter (Q1, Q2, Q3, या Q4) और उस quarter का आखिरी महीना determine करता है। फिर इन values का उपयोग Table_29 और CommentWidget_1 के filter update करने के लिए किया जाता है, जिससे यह सुनिश्चित होता है कि दोनों एक ही quarter और period का data दिखाएँ। Script processing के दौरान एक loading message (showBusyIndicator) भी display करती है और बाद में उसे छिपा देती है। संक्षेप में, यह comment और data tables को selected fiscal period के साथ automatic रूप से synchronize रखता है।
Filter main table based on commenting model page filter:
function onSelect() : void
//on Input Control select
var BA = InputControl_3.getInputControlDataSource().getActiveSelectedMembers()[0];
console.log(BA.displayId);
var chk = InputControl_3.getInputControlDataSource().isAllMembersSelected();
if (chk===false)
{
//apply BA filter
Table_4.getDataSource().setVariableValue("ABU_00",BA.displayId);
console.log(chk);
}
if (chk===true)
{
// clear BA filter
Table_4.getDataSource().setVariableValue("ABU_00",[]);
console.log(chk);
}
यह SAC scripting function तब चलता है जब कोई user InputControl_3 में कोई value चुनता है। यह सबसे पहले selected Business Area (BA) प्राप्त करता है और isAllMembersSelected() का उपयोग करके जाँचता है कि क्या सभी सदस्य selected हैं। यदि सभी members selected नहीं हैं, तो यह ABU_00 variable को selected BA की ID पर set करके Table_4 पर एक filter लागू करता है। यदि सभी members selected हैं, तो यह variable को एक empty list ([]) पर set करके filter clear कर देता है। Script selected values और status को console में भी log करती है। संक्षेप में, यह users के selection के आधार पर table को dynamic रूप से filter या reset करता है।
Get all dimension info:
//on page initialize
var xyz=Table_3.getDataSource().getDimensions();
console.log(xyz);
यह SAC scripting code Table_3 के data source में used सभी dimensions को प्राप्त करता है और उन्हें console में display करता है। getDataSource().getDimensions() command dimension names की एक list (array) लौटाता है, जैसे "Country", "Product", "Year", आदि, जो table data की structure को define करते हैं। ये dimension उन categories या fields का प्रतिनिधित्व करते हैं जिनके आधार पर data को group या filter किया जाता है। console.log(xyz); का उपयोग करके, script इस list को browser console में print करती है ताकि developers देख सकें या debug कर सकें कि table के data source में वर्तमान में कौन से dimension उपलब्ध हैं। यह table की structure को समझने के लिए उपयोगी है।
Filter table & comments based on page Quarter filter:
//Month
var getMonth=InputControl_2.getInputControlDataSource().getActiveSelectedMembers();
console.log("Month:");
console.log(getMonth[0].id);
console.log(getMonth[0].description);
//Year
var getYear=InputControl_1.getInputControlDataSource().getActiveSelectedMembers();
console.log("Year:");
console.log(getYear[0].id);
console.log(getYear[0].description);
var yy=(getYear[0].id.substring(0,4));
console.log("yy:");
console.log(yy);
//refresh table
if(getMonth[0].id === "10"){
Table_1.getDataSource().setVariableValue("V_FPER", yy+"0" + getMonth[0].id);
console.log("yy:"+"single zero");
}
else if(getMonth[0].id === "11"){
Table_1.getDataSource().setVariableValue("V_FPER", yy+"0" + getMonth[0].id);
console.log("yy:"+"single zero");
}
else if(getMonth[0].id === "12"){
Table_1.getDataSource().setVariableValue("V_FPER", yy+"0" + getMonth[0].id);
console.log("yy:"+"single zero");
}
else
{
Table_1.getDataSource().setVariableValue("V_FPER", yy+"00" + getMonth[0].id);
console.log("yy:"+"double zero");
}
यह SAC scripting code दो input controls से selected month और year को पढ़ता है और तदनुसार table filter को update करता है। यह सबसे पहले InputControl_2 (month) और InputControl_1 (year) के लिए active selection प्राप्त करता है, फिर उनकी IDs और description log करता है। यह वर्ष के पहले चार अंकों को yy (उदाहरण के लिए, "2025") के रूप में निकालता है। Selected month के आधार पर, यह एक formatted fiscal period value (V_FPER) बनाता है - month number के आधार पर एक या दो शून्य जोड़कर (उदाहरण के लिए, "202501" या "202510")। अंत में, यह data को ठीक से refresh और filter करने के लिए इस value को Table_1 में एक variable के रूप में set करता है।
Get model id:
//get model id
var tt=Application.getInfo();
console.log(tt);
यह SAC scripting code SAP Analytics Cloud में current application environment के बारे में जानकारी प्राप्त करने के लिए Application.getInfo() का उपयोग करता है। लौटाए गए data (variable tt में store) में application का name, version, language, theme और users जानकारी जैसे details शामिल होते हैं। console.log(tt); command फिर इस जानकारी को debugging या review के लिए browser के console पर print करता है। Developers अक्सर script execution के दौरान context-related data की जाँच करने के लिए इस function का उपयोग करते हैं, जैसे यह पहचानना कि कौन सा user या environment (test या production) वर्तमान में active है। संक्षेप में, यह चल रहे SAC application के बारे में महत्वपूर्ण details तक पहुँचने और उन्हें display करने का एक quick तरीका है।
// get fiscal year
var p1=Table_WorkingCapital.getDataSource().getVariableValues("V_FPER")[0];
console.log(p1);
यह SAC scripting code Table_WorkingCapital से जुड़े data source से "V_FPER" नामक एक story variable (जो आमतौर पर एक fiscal period का प्रतिनिधित्व करता है) का value प्राप्त करता है। getVariableValues("V_FPER")[0] function "V_FPER" को assigned values की list से पहला variable object प्राप्त करता है। इस object में type (single, multiple, या range) और actual selected values जैसे विवरण होते हैं। console.log(p1); line फिर इस variable की जानकारी console पर debugging या यह जाँचने के लिए print करती है कि वर्तमान में कौन सी fiscal period लागू है। यह developers को application के अन्य भागों में variable values को verify या reuse करने में मदद करती है।
// get all the dimensions
var xx=Table_30.getDataSource().getDimensions();
console.log(xx);
यह SAC scripting code Table_30 के data source से सभी dimension को प्राप्त करता है और उन्हें console में display करता है। getDataSource().getDimensions() command, table के dataset के आधार पर, "Country", "Product", "Year" या "Customer" जैसे dimension के नामों की एक list (array) लौटाता है। ये dimension define करते हैं कि table के data को कैसे group, categorize या filter किया जाता है। console.log(xx); statement browser console पर dimension की पूरी list print करता है। यह developers के लिए table के model में उपलब्ध dimension की जाँच करने में मददगार है, खासकर जब data display को filter करने, sort करने या dynamic रूप से modify करने के लिए script बनाते हैं।
// set story filter & refresh table
Table_WorkingCapital.getDataSource().setVariableValue("V_FPER",yy+"00"+mnth2);
यह SAC scripting line table के data source में एक story variable value set करती है। यहाँ, Table_WorkingCapital एक table widget को represent करता है, और "V_FPER" variable का नाम है (संभवतः एक financial period का प्रतिनिधित्व करता है)। Function setVariableValue("V_FPER", yy + "00" + mnth2) वर्ष (yy) और month (mnth2) को एक string में combine करके उस variable को एक नया value प्रदान करता है, जैसे May 2024 के लिए 2024005। यह selected period के अनुसार table के data को update करता है, और इसकी content को automatic रूप से refresh करता है। इसका उपयोग अक्सर तब किया जाता है जब users कोई month और year चुनते हैं, और script dynamic रूप से data view को accordingly बदल देती है।
//Application.getFileDataSource("B9006B832A7049795432AB51DEFB002D").setVariableValue("V_FPER",p1);
Table_WorkingCapital.getDataSource().refreshData();
यह SAC scripting line Table_WorkingCapital table में data को refresh या reload करती है। getDataSource().refreshData() function SAP Analytics Cloud को connected data source (उदाहरण के लिए, कोई model या live connection) से latest data पुनः प्राप्त करने के लिए कहता है। यह सुनिश्चित करता है कि कोई भी recent changes —जैसे update किए गए variable value, filter या input selection—table में सही ढंग से लागू और प्रदर्शित हों। सरल शब्दों में, यह सबसे current data प्राप्त करने के लिए "Refresh" button दबाने जैसा काम करता है। यह command variables, filters या input controls को modify करने के बाद उपयोगी होता है ताकि यह सुनिश्चित हो सके कि table update किए गए परिणाम दिखाए।
Filter Dimensions in table:
var v_memberInfos = ArrayUtils.create(Type.MemberInfo);
v_memberInfos.push({id:"US",description:""});
v_memberInfos.push({id:"DE",description:""});
Table_1.getDataSource().setDimensionFilter("ZCNTRY",v_memberInfos);
यह SAC scripting code Table_1 को filer करके केवल specific countries का data दिखाता है।
सबसे पहले, यह ArrayUtils.create(Type.MemberInfo) का उपयोग करके सदस्य जानकारी रखने के लिए एक empty list(v_memberInfos) बनाता है। फिर, यह उस list में दो country IDs — “US” (United States) और “DE” (Germany) — जोड़ता है। प्रत्येक entry में एक ID (filter के लिए used) और एक optional description होता है।
अंत में, Table_1.getDataSource().setDimensionFilter("ZCNTRY", v_memberInfos); इस list को Table_1 के ZCNTRY (country) dimension पर filter के रूप में लागू करता है, और केवल उन्हीं देशों से संबंधित data दिखाता है।
संक्षेप में, यह script America और Germany के लिए Table_1 को dynamic रूप से filter करती है।
Filter Measures in table:
//Filter specific measure in table
var v_memberInfos = ArrayUtils.create(Type.MemberInfo);
v_memberInfos.push({id:"6MU9WYQ1ZB8C1B5OA6R0CZPPW",description:"2408A"});
Table_57.getDataSource().setDimensionFilter("@MeasureDimension",v_memberInfos);
//remove measure filter from table
Table.removeDimension(Alias.MeasureDimension); Table.getDataSource().removeDimensionFilter(Alias.MeasureDimension);
//add measure filter from table
Table.addDimensionToColumns(Alias.MeasureDimension); Table.getDataSource().setDimensionFilter(Alias.MeasureDimension,"Id of the measure");
//------------------------------------------------------------------------
var measures = Table_57.getDataSource().getMeasures();
var measure = measures[0];
console.log(measure.description);
console.log(measure.dimensionId);
console.log(measure.id);
console.log(measure.modelId);
//------------------------------------------------------------------------
// practical example:
var array = Table_57.getDataSource().getResultSet();
console.log(array);
console.log(array[0]);
console.log(array[0][Alias.MeasureDimension].id);
var v_memberInfos = ArrayUtils.create(Type.MemberInfo);
//"2408A"
v_memberInfos.push({id:array[0][Alias.MeasureDimension].id,description:array[0][Alias.MeasureDimension].description});
//"2308A"
v_memberInfos.push({id:array[1][Alias.MeasureDimension].id,description:array[1][Alias.MeasureDimension].description});
//"YoY"
v_memberInfos.push({id:array[2][Alias.MeasureDimension].id,description:array[2][Alias.MeasureDimension].description});
//"2312A FY"
v_memberInfos.push({id:"6MU9WYQ1ZB8AB0S0LQWY98TOW",description:"2312A FY"});
Table_57.getDataSource().setDimensionFilter("@MeasureDimension",v_memberInfos);
यह SAC script Table_57 में measures को dynamic रूप से filter और manage करती है। यह सबसे पहले measures की एक list (v_memberInfos) बनाती है और table को उसकी internal ID का उपयोग करके केवल एक specific measure ("2408A") दिखाने के लिए filter करती है। फिर यह removeDimensionFilter और setDimensionFilter का उपयोग करके measure filter को हटाने और पुनः लागू करने का तरीका दिखाती है।
इसके बाद, यह सभी measures को उनके details (description, dimension ID, आदि) के साथ retrieve और log करता है। अंत में, यह table का result set प्राप्त करता है, measure IDs और description निकालता है, कई measures (जैसे "2408A", "2308A", "YoY", "2312A FY") को जोड़ता है, और table display को update करने के लिए उन्हें एक measure filter के रूप में लागू करता है।
Add or remove dimension from table:
var sel = DropDown_1.getSelectedKey();
Table_1.getDataSource().removeDimensionFilter("Dim1");
Table_1.getDataSource().setDimensionFilter("Dim1",sel);
Table_1.addDimensionToRows("CustomerUnit",2);
Table_1.removeDimension("CustomerAccountGroup");
Table_1.removeDimension("CustomerReportingGroup");
Table_1.removeDimension("Version");
Table_1.removeDimension("TopContributor");
यह SAC script users के dropdown selection के आधार पर Table_1 में प्रदर्शित data को update करती है। यह सबसे पहले DropDown_1 से selected key प्राप्त करती है और Dim1 dimension पर मौजूद किसी भी filter को हटा देती है। फिर यह selected key (sel) का उपयोग करके एक नया dimension filter लागू करती है। इसके बाद, यह detailed data दिखाने के लिए table rows (position 2 पर) में CustomerUnit dimension जोड़ती है। अंत में, यह अनावश्यक dimensions — CustomerAccountGroup, CustomerReportingGroup, Version, और TopContributor — को हटा देती है ताकि table view सरल हो जाए और users के वर्तमान selection के आधार पर केवल relevant data ही रखा जा सके।
Get specific measure from table:
//Using a table with 1 dimension & 1 measure this seems to work
var arr = Chart_1.getDataSource().getResultSet();
var value = ArrayUtils.create(Type.number);
for (var i=0;i<arr.length;i++)
{var string = arr[i][Alias.MeasureDimension].formattedValue;
var number = ConvertUtils.stringToNumber(string);
value.push(number);}
console.log(value);
यह SAC script chart के data source से numeric value निकालती है। सबसे पहले, यह getResultSet() का उपयोग करके Chart_1 से सभी data rows प्राप्त करती है। फिर यह value नामक एक empty number array बनाती है। Result set की प्रत्येक row में एक loop चलता है, measure के formattedValue (जो एक string है) को पढ़ता है, ConvertUtils.stringToNumber() का उपयोग करके उसे एक number में परिवर्तित करता है, और उसे value array में store करता है। अंत में, यह console में value array को print करता है। यह script scripting में calculation या custom analysis के लिए chart से measure value collect करने के लिए उपयोगी है।
Get specific dimension from table:
var str="";
var selections = Chart_1.getDataSource().getDataSelections();
console.log(selections);
for (var i=0; i<selections.length; i++){
str =str+selections[i].EmployeeUserName+";";
};
console.log(str);
यह SAC script Chart_1 से selected data point एकत्र करती है। यह पहले एक empty string variable str बनाता है। फिर getDataSelections() का उपयोग करके chart में किए गए सभी data selections को पुनः प्राप्त करता है। Script प्रत्येक selected item माध्यम से loop करती है और प्रत्येक selection से EmployeeUserName को str variable में जोड़ती है, उन्हें semicolons से अलग करती है। अंत में, यह console में combine string को print करता है। यह तब उपयोगी होता है जब आप SAP Analytics Cloud scripting में logging, filtering या further processing के लिए chart से सभी selected employees के नामों को एक ही text format में capture या display करना चाहते हैं।
Drill down table:
//Table_1 - onSelect:
Application.setAutomaticBusyIndicatorEnabled(true);
var NoDim=Table_1.getDimensionsOnRows().length;
console.log(NoDim);
SelectionArray_Table1 = Table_1.getSelections();
var CurrentCoCd = SelectionArray_Table1[0]["0COMP_CODE"];
var CurrentGL = SelectionArray_Table1[0]["0GL_ACCOUNT"];
var CurrentDocNo = SelectionArray_Table1[0]["LFIN_DOC"];
console.log(CurrentCoCd);
console.log(CurrentGL);
console.log(CurrentDocNo);
Table_1.getDataSource().setRefreshPaused(true);
if (NoDim===1){
Table_1.getDataSource().setDimensionFilter("0COMP_CODE",CurrentCoCd);
Table_1.addDimensionToRows("0GL_Account",2);
}
if (NoDim===2){
Table_1.getDataSource().setDimensionFilter("0GL_ACCOUNT",CurrentGL);
Table_1.addDimensionToRows("0DOC_DATE",3);
Table_1.addDimensionToRows("LFIN_DOC",4);
Table_1.addDimensionToRows("0ORG_DOC_NO",5);}
if (NoDim===5){
Table_1.getDataSource().setDimensionFilter("0GL_ACCOUNT",CurrentGL);
Table_1.addDimensionToRows("0FISCPER",3);
Table_1.addDimensionToRows("0DOC_CURRCY",7);
Table_1.addDimensionToRows("0LOC_CURRCY",8);
Table_1.addDimensionToRows("0ALLOC_NMBR",9);
Table_1.addDimensionToRows("CBKTXT",10);
Table_1.addDimensionToRows("0POSTXT",11);
Table_1.addDimensionToRows("0DCINDIC",12);
}
if (NoDim===12){
Table_1.getDataSource().setDimensionFilter("0GL_ACCOUNT",CurrentGL);
}
Table_1.getDataSource().setRefreshPaused(false);
Table_1.getDataSource().refreshData();
//Button_RemoveDimension2:
Application.setAutomaticBusyIndicatorEnabled(true);
var NoDim=Table_1.getDimensionsOnRows().length;
console.log(NoDim);
Table_1.getDataSource().setRefreshPaused(true);
if (NoDim===1){
}
if (NoDim===2){
Table_1.removeDimension("0GL_ACCOUNT");
Table_1.getDataSource().removeDimensionFilter("0COMP_CODE", CoCdArray);
}
if (NoDim===5){
Table_1.removeDimension("0DOC_DATE");
Table_1.removeDimension("LFIN_DOC");
Table_1.removeDimension("0ORG_DOC_NO");
Table_1.getDataSource().removeDimensionFilter("0GL_ACCOUNT");
}
if (NoDim===12){
Table_1.removeDimension("0FISCPER");
Table_1.removeDimension("0DOC_CURRCY");
Table_1.removeDimension("0ALLOC_NMBR");
Table_1.removeDimension("0POSTXT");
Table_1.removeDimension("0DCINDIC");
Table_1.removeDimension("0DOC_CURRCY");
Table_1.removeDimension("0LOC_CURRCY");
Table_1.removeDimension("CBKTXT");
}
Table_1.getDataSource().setRefreshPaused(false);
Table_1.getDataSource().refreshData();
//WelcomeChart3 - onSelect:
Application.setAutomaticBusyIndicatorEnabled(true);
Table_2.getDataSource().setDimensionFilter(Alias.MeasureDimension,["6MU9W....","6MU9W...."]);
Table_2.getDataSource().setDimensionFilter("0GL_ACCOUNT",GACaccounts1);
Table_2.addDimensionToRows("0GL_ACCOUNT");
GAC_Open_Items.setSelectedKeys('Tab_2');
यह SAC scripting उदाहरण user के selections के आधार पर एक table को dynamic रूप से expand और filter करता है। जब कोई user Table_1 में एक row चुनता है, तो script getDimensionsOnRows() का उपयोग करके जाँचती है कि वर्तमान में कितने dimension (levels) दिखाई दे रहे हैं। इस count के आधार पर, यह filter लागू करता है (जैसे company code, GL account, या document number) और अधिक detail dimension (जैसे, posting text, fiscal period, currency) जोड़ता है। बेहतर प्रदर्शन के लिए update के दौरान table refresh को रोक दिया जाता है, फिर उसे फिर से शुरू करके refresh किया जाता है। एक अन्य भाग button पर click करने पर dimensions को हटा देता है। अंत में, chart selection, interactive drill-down analysis के लिए GL accounts और values के आधार पर Table_2 को filter करता है।
