SAC scripting for Story Variable/Filter

SAC scripting for Story Variable/Filter

Change Story variable filter on page load:

                var current_date = new Date(Date.now());
var date_new_millisec = current_date.setDate(current_date.getDate() - 0);
var new_date = new Date(date_new_millisec);
var date_new_format = new_date.toJSON().slice(0,10);
var dd = ConvertUtils.stringToInteger(date_new_format.substring(8,10));
var mm=ConvertUtils.stringToInteger(date_new_format.substring(5,7));
var yy=ConvertUtils.stringToInteger(date_new_format.substring(0,4));
console.log(date_new_format);
console.log(dd);
console.log(mm);
console.log(yy);
if(mm<=9){
   var mnth="0"+mm.toString();
   }else{
   mnth=mm.toString();
   }
console.log(mnth);
if(dd>=10)
{
Application.getFileDataSource("t.8:Cbjg01n2p2hkp08ki5r0pbd448").setVariableValue("V_FPER",yy.toString()+"0"+mnth);
}
//Change Story variable filter in URL:
//https://ericsson.eu10.hcs.cloud.sap/sap/fpa/ui/tenants/54d9f/app.html#/story2&/s2/AE83207A27797A469B5C5725CCE9C08/?f01Model=t.8:Cbjg01n2p2hkp08ki5r0pbd448&f01Par=0FISCPER&f01Val=2024009&mode=view
//Change Story variable filter in URL on button click:
NavigationUtils.openStory("AE83207A27797A469B5C5725CCE9C08""2242a320-dc17-45ab-a11c-996fe3e9cbbb",
  [UrlParameter.create("f01Model","t.8:Cbjg01n2p2hkp08ki5r0pbd448"),
UrlParameter.create("f01Par","0FISCPER"),
UrlParameter.create("f01Val","2024009")
],true);
//Change Story Dimension filter in URL on button click:
NavigationUtils.openStory("AE83207A27797A469B5C5725CCE9C08", "2242a320-dc17-45ab-a11c-996fe3e9cbbb",
  [UrlParameter.create("v01model","t.8:Cbjg01n2p2hkp08ki5r0pbd448"),
UrlParameter.create("v01Par","0FISCPER"),
UrlParameter.create("v01Val","009.2024")
],true);

इस code में हम यह समझेंगे कि:

  • Current Date कैसे निकालते हैं
  • Date को Year, Month, Day में कैसे तोड़ते हैं
  • Fiscal Period (0FISCPER) के लिए Variable Value कैसे set करते हैं
  • Button Click पर Story को URL Parameter के साथ कैसे Open करते हैं


🔹Step 1: Current Date निकालना
var current_date = new Date(Date.now());
🔹यह line system की आज की तारीख और समय को पकड़ती है।
Date.now() current timestamp देता है और new Date() उसे date object में बदल देता है।
उदाहरण:
👉 अगर आज की तारीख है 15 September 2024, तो current_date में वही value होगी।


🔹 Step 2: Date से Day घटाना / बढ़ाना
var date_new_millisec = current_date.setDate(current_date.getDate() - 0);
🔹 getDate() → आज का दिन देता है
🔹 setDate() → नया दिन set करता है
👉 यहाँ -0 लिखा है, यानी आज की ही तारीख ली जा रही है
अगर आप कल की तारीख चाहते हैं:
current_date.getDate() - 1


🔹 Step 3: New Date Object बनाना
var new_date = new Date(date_new_millisec);
🔹 Milliseconds को वापस Date format में convert किया गया।


🔹 Step 4: Date को YYYY-MM-DD Format में बदलना
var date_new_format = new_date.toJSON().slice(0,10);
🔹 toJSON() → Date को string में बदल देता है
🔹 slice(0,10) → सिर्फ YYYY-MM-DD निकालता है
📌 Example Output:
2024-09-15


🔹 Step 5: Date को Day, Month, Year में तोड़ना
var dd = ConvertUtils.stringToInteger(date_new_format.substring(8,10));
var mm=ConvertUtils.stringToInteger(date_new_format.substring(5,7));
var yy=ConvertUtils.stringToInteger(date_new_format.substring(0,4));
🔹 substring() से हम Date string के parts निकालते हैं
🔹 ConvertUtils.stringToInteger() string को number में बदल देता है
📌 Output:
dd → 15
mm → 9
yy → 2024


🔹 Step 6: Console Log से Debug करना
console.log(date_new_format);
console.log(dd);
console.log(mm);
console.log(yy);
🔹 SAC Script Debug Mode में values देखने के लिए उपयोगी
👉 Error ढूंढने में मदद करता है


🔹 Step 7: Month को 2 Digit Format में बदलना
if(mm<=9){
   var mnth="0"+mm.toString();
   }else{
   mnth=mm.toString();
   }
🔹 Fiscal Period में Month हमेशा 2 digit होता है
👉 9 → 09
👉 11 → 11
📌 Example:
09


🔹 Step 8: Variable (0FISCPER) में Value Set करना
if(dd>=10)
{
Application.getFileDataSource("t.8:Cbjg01n2p2hkp08ki5r0pbd448").setVariableValue("V_FPER",yy.toString()+"0"+mnth);
}
🔹 यह SAC Model का Story Variable set करता है
🔹 Variable Name: V_FPER
🔹 Value Format: YYYY0MM
📌 Example:
2024009
✔️ इसका मतलब:
Year = 2024
Month = 09


🔹 Step 9: URL से Story Variable Filter बदलना
https://.../story2...?f01Model=MODEL_ID
&f01Par=0FISCPER
&f01Val=2024009
🔹 इसका उपयोग तब होता है जब आप URL से सीधे Story open करते हैं
🔹 f01Val में Fiscal Period pass होता है


🔹 Step 10: Button Click पर Story Open करना (Variable Filter)
NavigationUtils.openStory("AE83207A27797A469B5C5725CCE9C08""2242a320-dc17-45ab-a11c-996fe3e9cbbb",  
[UrlParameter.create("f01Model","t.8:Cbjg01n2p2hkp08ki5r0pbd448"),
UrlParameter.create("f01Par","0FISCPER"),
UrlParameter.create("f01Val","2024009")
],true);
🔹 Button Click करने पर:
नई Story open होती है
Variable 0FISCPER = 2024009 auto apply हो जाता है
📌 Real-life Use:
👉 Current Month के data के साथ नई Story खोलना


🔹 Step 11: Dimension Filter के साथ Story Open करना
NavigationUtils.openStory("AE83207A27797A469B5C5725CCE9C08", "2242a320-dc17-45ab-a11c-996fe3e9cbbb",  [UrlParameter.create("v01model","t.8:Cbjg01n2p2hkp08ki5r0pbd448"),
UrlParameter.create("v01Par","0FISCPER"),
UrlParameter.create("v01Val","009.2024")
],true);
🔹 यहाँ Variable नहीं, बल्कि Dimension Filter लगाया गया है
🔹 Format: MM.YYYY
📌 Example:
009.2024


Hide filter panel

FilterPanel.setVisible(false);

SAP Analytics Cloud (SAC) Analytic Applications में Filter Panel widget को user interface से छिपाने के लिए setVisible(false) method का उपयोग किया जाता है। setVisible(false) specified widget के visibility property को बदल देती है, जिससे यह background में सक्रिय रहते हुए users के लिए invisible हो जाता है। यह तब उपयोगी होता है जब आप data loading, page initialization, या condition पूरी होने पर filter को अस्थायी रूप से छिपाना चाहते हैं। Developers अक्सर इसका उपयोग अधिक स्पष्ट, guided dashboards बनाने के लिए करते हैं जहाँ filter केवल आवश्यकता पड़ने पर ही दिखाए जाते हैं, जिससे users अनुभव बेहतर होता है और key visual elements या results पर ध्यान केंद्रित रहता है।


Show filter panel

FilterPanel.setVisible(true);

SAP Analytics Cloud (SAC) Analytic Applications में Filter Panel widget को screen पर visible बनाने के लिए setVisible(true) function का उपयोग किया जाता है। setVisible(true) function widget के visibility property को बदलता है, जिससे users इसे देख और उससे interact कर सकते हैं। यह command अक्सर data load होने के बाद या जब users की किसी action—जैसे किसी button पर click करने—के लिए filter display करने की आवश्यकता होती है, तब उपयोग किया जाता है। यह dynamic और interactive dashboards बनाने में मदद करता है जहाँ element contextually रूप से दिखाई देते हैं, जिससे usability और focus में सुधार होता है। Developers आमतौर पर इसे setVisible(false) के साथ जोड़कर conditions के आधार पर visibility को नियंत्रित करते हैं, जिससे एक smoother और अधिक guided users experience सुनिश्चित होता है।


Check filter panel

FilterPanel.isVisible();

SAP Analytics Cloud (SAC) Analytic Applications में इसका उपयोग यह जाँचने के लिए किया जाता है कि Filter Panel widget वर्तमान में screen पर दिखाई दे रहा है या नहीं। function isVisible() एक Boolean value लौटाता है - यदि widget दिखाई दे रहा है तो true, या यदि छिपा हुआ है तो false। यह conditional scripting में विशेष रूप से उपयोगी है, जहाँ widget की visible स्थिति के आधार पर विभिन्न actions करने की आवश्यकता होती है। उदाहरण के लिए, developers इसका उपयोग display settings को toggle करने, केवल panel दिखाई देने पर ही logic चलाने, या layout को dynamic रूप से manage करने के लिए कर सकते हैं। यह runtime के दौरान users के अनुकूल और interactive dashboard behavior बनाए रखने में मदद करता है।

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

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

और नया पुराने