Debug SAC script issues with guided analysis and common error resolution
Debugs SAC scripts with guided analysis, common error resolution, and step-by-step troubleshooting workflows.
/plugin marketplace add secondsky/sap-skills/plugin install sap-sac-scripting@sap-skillsProvide guided SAC script debugging assistance.
Ask the user for:
Cause: Calling a method that doesn't exist on the object
Check:
// Wrong: Method name typo or doesn't exist
Chart_1.getDataSoruce(); // Typo!
// Correct:
Chart_1.getDataSource();
Resolution:
Cause: Object is null/undefined when accessing property
Check:
// Wrong: selections might be empty
var value = Chart_1.getSelections()[0]["Location"];
// Correct: Check array length first
var selections = Chart_1.getSelections();
if (selections.length > 0) {
var value = selections[0]["Location"];
}
Resolution:
Cause: Trying to iterate over non-array
Check:
// Wrong: getSelections() might return null
for (var sel of Chart_1.getSelections()) { }
// Correct: Check for array
var selections = Chart_1.getSelections() || [];
for (var i = 0; i < selections.length; i++) { }
Cause: Dimension name doesn't match model exactly
Check:
// Wrong: Case mismatch or wrong name
ds.setDimensionFilter("location", "US"); // lowercase!
// Correct: Use exact dimension name from model
ds.setDimensionFilter("Location", "US"); // Match model case
Resolution:
// Add at script start
console.log("=== Script started ===");
// Log variables
console.log("Widget:", typeof Chart_1, Chart_1);
console.log("DataSource:", Chart_1.getDataSource());
console.log("Selections:", JSON.stringify(Chart_1.getSelections()));
// Log before operations
console.log("Applying filter:", dimensionName, filterValue);
sandbox.worker.main.*.js)// Check widget exists
if (typeof Chart_1 !== "undefined" && Chart_1 !== null) {
var ds = Chart_1.getDataSource();
if (ds !== null) {
// Safe to proceed
ds.setDimensionFilter("Location", "US");
} else {
console.error("Chart_1 has no data source assigned");
}
} else {
console.error("Chart_1 widget not found");
}
Widget Issues:
Data Source Issues:
API Issues:
Selection Issues:
// Test 1: Widget exists
console.log("Test 1 - Widget:", Chart_1);
// Test 2: Data source
console.log("Test 2 - DS:", Chart_1.getDataSource());
// Test 3: Get data
console.log("Test 3 - ResultSet:", Chart_1.getDataSource().getResultSet());
// Test 4: Selections
console.log("Test 4 - Selections:", Chart_1.getSelections());
// Add to event handler to confirm it fires
console.log("EVENT FIRED: onSelect at " + new Date().toISOString());
| Error | Likely Cause | Fix |
|---|---|---|
| undefined is not a function | Wrong method name | Check API docs |
| Cannot read property X of undefined | Null object access | Add null checks |
| X is not iterable | Non-array iteration | Verify array type |
| No error but no effect | Wrong dimension name | Check model schema |
| Script doesn't run | Event not connected | Check widget events |
Based on the provided error information, analyze the issue and provide: