on 2025 Feb 24 9:58 PM
Can anyone show me how to code a custom script in SAC optimized design story (on initialization of page) to load the measure values in a table into a variable and then loop through the measure values to check for a condition for each of the values.
I want to create a conditional alert but not able to add code successfully to extract measure values like described above. I have only one measure in the table.
Regards,
Request clarification before answering.
Hi ,
consider the below example and sample code:
Example :
Your table is named Table_1.
Your measure is in column index 0 (since there's only one measure).
Your condition is, for example, checking if any value exceeds 1000.
Ref. code :
let ds = Table_1.getDataSource();
ds.getData({
includeDimensions: false,
includeMeasures: true
}).then(function(data) {
let measureValues = [];
for (let i = 0; i < data.length; i++) {
let measureValue = data[i][0]; // First column contains the measure value
measureValues.push(measureValue);
}
let alertTriggered = false;
for (let i = 0; i < measureValues.length; i++) {
if (measureValues[i] > 1000) { // Your condition
alertTriggered = true;
break; // Exit loop on first match
}
}
if (alertTriggered) {
Application.showMessage(ApplicationMessageType.Error, "Warning: Some values exceed the limit!");
}
});
Hope this helps,
Thank you!
Giri
SAP - PSCC
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
As a simple example, the code below will loop through all measure values in the table,
As soon as a value is greater than 282 - the script will launch an application message or a text box etc.
I've created 2 buttons one for each...
var arr = Table_3.getDataSource().getResultSet();
for (var i=0;i<arr.length;i++)
{ var string = arr[i][Alias.MeasureDimension].rawValue;
var number = ConvertUtils.stringToNumber(string);
if(number>282) { Text_1.setVisible(true); break }} var arr = Table_3.getDataSource().getResultSet();
for (var i=0;i<arr.length;i++)
{ var string = arr[i][Alias.MeasureDimension].rawValue;
var number = ConvertUtils.stringToNumber(string);
if(number>282) { Application.showMessage(ApplicationMessageType.Info,"test"); break }} You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @JBARLOW, the script you provided worked to pop a text message on fulfillment of the condition coded. I am trying to do the same to trigger an email having problem with it as the email is getting delivered even if the condition in the story is not fulfilled.
Is the requirement to send email notifications to intended recipients on a scheduled basis whenever the particular condition is met (for instance, revenue > 120000) feasible in SAC?. Please let me know if you are aware of it or tried this earlier?
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.