SAC scripting for Toggle button

SAC scripting for Toggle button

Show/hide table tab on switch button toggle:

//on switch button

if (SWH_TogglePCodes.isOn()){
TABS_IS.setSelectedKey("With_Exclusion");
Application.showMessage(ApplicationMessageType.Info,"IPR is excluded");
} else {
TABS_IS.setSelectedKey("Without_Exclusion");
Application.showMessage(ApplicationMessageType.Info,"IPR is included");
}


Filter to Exclude Product codes 1:

//apply on switch button

var ExcludePCodes = ArrayUtils.create(Type.string);
//Current set of p-codes needed to exclude/include - 5000,5001,72,72A,72CL,72I,72NW
ExcludePCodes = ["5000","5001","0072","72A","72CL","72NW","72I"];
if(Switch_1.isOn()===true)
{
// Get selected members from Input Control
// Apply background filter to Table
console.log(ExcludePCodes);

Table_30.getDataSource().removeDimensionFilter("CFIREPCOD");
Table_30.getDataSource().setHierarchy("CFIREPCOD",'__FLAT__');
Table_30.getDataSource().setDimensionFilter("CFIREPCOD",{values: ExcludePCodes, exclude: true});

Table_48.getDataSource().removeDimensionFilter("CFIREPCOD");
Table_48.getDataSource().setHierarchy("CFIREPCOD",'__FLAT__');
Table_48.getDataSource().setDimensionFilter("CFIREPCOD",{values: ExcludePCodes, exclude: true});

Table_49.getDataSource().removeDimensionFilter("CFIREPCOD");
Table_49.getDataSource().setHierarchy("CFIREPCOD",'__FLAT__');
Table_49.getDataSource().setDimensionFilter("CFIREPCOD",{values: ExcludePCodes, exclude: true});

Table_50.getDataSource().removeDimensionFilter("CFIREPCOD");
Table_50.getDataSource().setHierarchy("CFIREPCOD",'__FLAT__');
Table_50.getDataSource().setDimensionFilter("CFIREPCOD",{values: ExcludePCodes, exclude: true});

console.log("True");
}
else
{
Table_30.getDataSource().removeDimensionFilter("CFIREPCOD");
//Table_30.getDataSource().refreshData();

Table_48.getDataSource().removeDimensionFilter("CFIREPCOD");
//Table_48.getDataSource().refreshData();

Table_49.getDataSource().removeDimensionFilter("CFIREPCOD");
//Table_49.getDataSource().refreshData();

Table_50.getDataSource().removeDimensionFilter("CFIREPCOD");
//Table_50.getDataSource().refreshData();

console.log("False");
}


Filter to Exclude Product codes 2:

//apply on switch button

// write below code on switch to call method:
Methods.FilterPCodes([Table_48, Table_30, Table_49, Table_50],"CFIREPCOD",Switch_1.isOn());

// create a method & write below code in it to filter in/filter out:
var ExcludePCodes = ArrayUtils.create(Type.string);

//Current set of p-codes needed to exclude/include - 5000,5001,72,72A,72CL,72I,72NW
ExcludePCodes = ["5000","5001","72","72A","72CL","72NW","72I"];

/*
var counter = 0;
var bool = 0;
if(gNewPCodes.length<1){
for (var l=0; l<gPCodes.length;l++){
bool = 0;
for (var k=0; k<ExcludePCodes.length; k++){
if ( (ExcludePCodes[k] !== gPCodes[l]) ){
bool = bool+1;
}
}
if (bool === ExcludePCodes.length){ 
gNewPCodes[counter] = gPCodes[l];
counter++; }
}
}
console.log(gNewPCodes);
*/

var len = TableNames.length;

if (OnOrOff){
//console.log("true");
for(var i=0;i<len;i++){
TableNames[i].getDataSource().setHierarchy(DimensionName,'__FLAT__');
TableNames[i].getDataSource().setDimensionFilter(DimensionName,{values: ExcludePCodes, exclude: true});
}
Application.showMessage(ApplicationMessageType.Info,"This might take some time as P-Codes: \"5000,5001,72,72A,72CL,72NW\" are being excluded from the data.");
} else {
//console.log("false");
for(var j=0;j<len;j++){
TableNames[j].getDataSource().removeDimensionFilter(DimensionName);
}
Application.showMessage(ApplicationMessageType.Info,"All P-Codes are now included in the data.");
}


Show / Hide Widget

if (Switch_1.isOn()) {
Table_1.setVisible(true);
} else {
Table_1.setVisible(false);

यह SAC scripting code एक switch button का उपयोग करके table की visibility को नियंत्रित करता है। जब switch (Switch_1) ON होता है, तो Table_1.setVisible(true) command table को users के लिए visible बनाता है। जब switch OFF होता है, तो Table_1.setVisible(false) table को view से छिपा देता है। यह simple conditional logic users को dashboard elements को interactive रूप से दिखाने या छिपाने की अनुमति देता है, जिससे interface clean और focused रहता है। यह विशेष रूप से तब उपयोगी होता है जब users specific components, जैसे detailed data tables को केवल आवश्यकता पड़ने पर ही देखना चाहते हैं—SAP Analytics Cloud applications में user experience और visual clarity दोनों को बेहतर बनाता है।


Apply / Remove Filter

var ds = Table_1.getDataSource();
if (Switch_1.isOn()) {
ds.setDimensionFilter("Country", ["India"]);
} else {
ds.removeDimensionFilter("Country");
}
Application.refreshData();

यह SAC scripting code switch button की स्थिति के आधार पर किसी table पर data filter लागू या हटाता है। ds variable, getDataSource() का उपयोग करके Table_1 के data source को पुनः प्राप्त करता है। यदि switch (Switch_1) ON है, तो "Country" dimension पर एक filter लागू होता है, जो केवल "India" का data दिखाता है। यदि switch OFF है, तो filter हटा दिया जाता है, और सभी देशों को फिर से display करता है। अंत में, Application.refreshData() latest filter changes को दर्शाने के लिए table को refresh करता है। यह interactive logic users को filter को आसानी से ON और OFF करने की अनुमति देता है, जिससे SAP Analytics Cloud dashboard में data analysis का flexibility बेहतर होता है।


Enable / Disable User Input

var editable = Switch_1.isOn(); InputField_1.setEnabled(editable); InputField_2.setEnabled(editable);

यह SAC scripting code switch button की स्थिति के आधार पर input field को editable योग्य बनाता है या नहीं, इसे नियंत्रित करता है। "editable" variable, isOn() method का उपयोग करके Switch_1 की ON/OFF state को store करता है। यदि switch ON (true) है, तो InputField_1 और InputField_2 दोनों enabled हो जाते हैं, जिससे users value type या modify कर सकते हैं। यदि switch OFF (false) है, तो input field enabled हो जाते हैं, जिससे कोई भी edit नहीं हो पाता। यह approach data entry method—जैसे "View" और "Edit" स्थितियों के बीच switch करने—को नियंत्रित करने के लिए उपयोगी है, जिससे यह सुनिश्चित होता है कि users केवल तभी input modify कर सकते हैं जब स्पष्ट रूप से अनुमति दी गई हो, जिससे SAC applications में security और data consistency बेहतर होती है।


Toggle Application Theme

if (Switch_1.isOn()) {
Application.setTheme("sap_fiori_3_dark");
} else {
Application.setTheme("sap_fiori_3");
}

इस SAC scripting code का उपयोग किसी application में switch button का उपयोग करके light और dark रंग की theme के बीच switch करने के लिए किया जाता है। जब switch (Switch_1) ON होता है, तो application theme "sap_fiori_3_dark" में बदल जाती है, जिससे बेहतर visibility या aesthetic संबंधी preference के लिए dark mode enable हो जाता है। जब switch OFF होता है, तो यह default "sap_fiori_3" light रंग की theme पर वापस आ जाता है। Application.setTheme() function page को reload किए बिना selected theme को dynamic रूप से लागू करता है। यह सुविधा SAP Analytics Cloud में dashboard को different viewing conditions या users preference के अनुकूल बनाकर, personalization की अनुमति देकर users experience को बेहतर बनाती है।


Refresh Data Manually

if (Switch_1.isOn()) {
Application.showBusyIndicator("Refreshing data...");
Application.refreshData();
Application.hideBusyIndicator();
Switch_1.setOn(false); // Reset to OFF
}

यह SAC scripting code data को manual रूप से refresh करने के लिए एक switch button का उपयोग करता है। जब switch (Switch_1) ON होता है, तो script सबसे पहले Application.showBusyIndicator() का उपयोग करके एक busy indicator message "Refreshing data..." display करती है ताकि users को सूचित किया जा सके कि processing जारी है। फिर, यह Application.refreshData() के साथ application के सभी data sources को refresh करता है। Refresh पूरा होने के बाद, busy indicator को Application.hideBusyIndicator() का उपयोग करके छिपा दिया जाता है। अंत में, Switch_1.setOn(false) के साथ switch को OFF कर दिया जाता है ताकि वह active न रहे। यह SAC application के भीतर data को interactive रूप से refresh करने के लिए एक clear, user-friendly प्रक्रिया बनाता है।


Control Visibility of Multiple Widgets

var state = Switch_1.isOn();
Chart_1.setVisible(state);
Table_1.setVisible(!state);

यह SAC scripting code switch button की स्थिति के आधार पर दो widget—Chart_1 और Table_1—की visiblity को नियंत्रित करता है। Variable state, isOn() method का उपयोग करके Switch_1 की ON/OFF condition को store करती है। यदि switch ON (true) है, तो Chart_1 visible हो जाता है और Table_1 छिप जाता है। यदि switch OFF (true) है, तो chart छिप जाता है और table दिखाई जाती है। यह simple logic users को एक ही switch का उपयोग करके विभिन्न data views (उदाहरण के लिए, chart view vs table view) के बीच toggle करने की अनुमति देता है, जिससे SAP Analytics Cloud में एक interactive और user-friendly dashboard अनुभव बनता है।


Conditional Action

if (Switch_1.isOn()) {
    Application.showMessage(ApplicationMessageType.Info, "Alert Mode Activated!"); } else {
    Application.showMessage(ApplicationMessageType.Info, "Alert Mode Deactivated!");
}

यह SAC scripting code switch button की स्थिति के आधार पर एक information message प्रदर्शित करता है। जब switch (Switch_1) ON होता है, तो यह "Alert Mode Activated!" संदेश display करता है, जो दर्शाता है कि alert mode enabled है। जब switch OFF होता है, तो यह "Alert Mode Deactivated!" display करता है, जो दर्शाता है कि alert mode disabled कर दिया गया है। Screen पर user-friendly notification display करने के लिए Application.showMessage() function का उपयोग ApplicationMessageType.Info parameters के साथ किया जाता है। यह script users को immediate feedback प्रदान करती है, जिससे उन applications में interactivity और clarity में सुधार होता है जहाँ alert या monitoring mode dynamic रूप से toggle किए जाते हैं।


Multi-Action Switch

if (Switch_1.isOn()) {
Application.showBusyIndicator("Switching to Advanced Mode...");
Chart_1.setVisible(true);
Table_1.setVisible(true);
Application.hideBusyIndicator();
} else {
Chart_1.setVisible(false);
Table_1.setVisible(false);
}

यह SAC scripting code एक switch button का उपयोग करके chart और table की visibility को नियंत्रित करता है। जब switch (Switch_1) ON होता है, तो system एक busy indicator संदेश "Switching to Advanced Mode..." display करता है, Chart_1 और Table_1 को visible बनाता है, और फिर प्रक्रिया पूरी होने पर busy indicator को छिपा देता है। जब switch OFF होता है, तो chart और table दोनों छिप जाते हैं। यह logic users को basic और advanced dashboard modes के बीच आसानी से toggle करने में मदद करता है, जिससे एक interactive अनुभव मिलता है और visibility change process के दौरान बेहतर user feedback process के लिए busy indicator का उपयोग करते हुए एक smooth transition बनाए रखा जाता है।

एक टिप्पणी भेजें

Please do not enter any spam link in the comment box.

और नया पुराने