cancel
Showing results for 
Search instead for 
Did you mean: 

Set story date filter via script to previous month

johnfeigs
Explorer

I want the users to be able to pick a month via a date picker. The date picker is based on a date input control (Filter --> Date -->  by Range --> create date input control).

I want to set this date input control initially to the previous month. And interestingly i managed to do that with the following script:

 

var cur_date = new Date(Date.now());
var jahr = cur_date.getFullYear();
var monat = cur_date.getMonth();
if (monat === 0){
monat = 12;
jahr = jahr - 1;
}

console.log(monat);
console.log(jahr);

var calenderYearCCD = CurrentDateTime.createCalendarDateTime({granularity: CalendarTimeGranularity.Month, year: jahr, month: monat});
console.log(monat);
Application.setCurrentDateTime(calenderYearCCD);

 
I got the last bit from here:
APIs für Story-Filter und Variablen verwenden | SAP Help Portal
btw: in the sample code is a bug:
johnfeigs_0-1708762538687.png

 

The "problem" is after my date picker is set, the script gives a very long error message and i have no clue how to fix it or worst case disable error messages (since the code seems to work just fine :-P)
 
 
Anyone who knows about these issues? Also would appreciate advise on a better date diff code than my crappy workaround.

Script execution failed for event "Page_1.onInitialization"

[FailedAction - Action: qmFilter.v1.refreshFilter@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.ChildActionFailed/Child action failed]
[FailedAction - Action: qmFilter.v1.setQMFilterModel@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.ChildActionFailed/Child action failed]
[FailedAction - Action: qmFilter.internal.updateExternalFilter@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.UnhandledError/Unhandled failure during external write operation.]
Cannot read properties of null (reading 'getName')
code: Store.ChildActionFailed
action: {instanceId: e, storeEntityType: 'qmFilter', type: 'qmFilter.v1.refreshFilter'}instanceId: e {idStr: '[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"…2-4815-b449-349141561035"},{"qmFilter":"fs4fic"}]', lastPair: {…}, debugKey: '[{"qmFilter":"fs4fic"},{"app":"MAIN_APPLICATION"},…Element":"59233173-2312-4815-b449-349141561035"}]'}storeEntityType: "qmFilter"type: "qmFilter.v1.refreshFilter"[[Prototype]]: Object
devMessage: Child action failed
sourceFailure: TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329
otherInfo: undefined
translatedMessage: undefined
actionId: undefined

TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329

[FailedAction - Action: qmFilter.v1.setQMFilterModel@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.ChildActionFailed/Child action failed]
[FailedAction - Action: qmFilter.internal.updateExternalFilter@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.UnhandledError/Unhandled failure during external write operation.]
Cannot read properties of null (reading 'getName')
code: Store.ChildActionFailed
action: {qmFilterModel: {…}, forceUpdate: true, delayUpdateFilterExpression: undefined, instanceId: e, storeEntityType: 'qmFilter', …}
devMessage: Child action failed
sourceFailure: TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329
otherInfo: undefined
translatedMessage: undefined
actionId: undefined

TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329

[FailedAction - Action: qmFilter.internal.updateExternalFilter@[{"app":"MAIN_APPLICATION"},{"story":"storyID"},{"viz2":"36142357-5011-4253-9497-625793662152"},{"DynamicRangeICElement":"59233173-2312-4815-b449-349141561035"},{"qmFilter":"fs4fic"}] - Error: Store.UnhandledError/Unhandled failure during external write operation.]
Cannot read properties of null (reading 'getName')
code: Store.UnhandledError
action: {qmFilterModel: {…}, oldQMFilterModel: {…}, applicationId: '30284444-3527-4318-b073-323831675324', forceUpdate: undefined, delayedFilterProcessing: false, …}
devMessage: Unhandled failure during external write operation.
sourceFailure: TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329
otherInfo: undefined
translatedMessage: undefined
actionId: -1

TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329

Cannot read properties of null (reading 'getName')

TypeError: Cannot read properties of null (reading 'getName')
at t.create (app.chunk.152.872d53fc57456ca18fc9.js:1:48270)
at y (112.main.8be267e7a88b8ad7766f.js:16:41060)
at Object.l (112.main.8be267e7a88b8ad7766f.js:16:41575)
at tv.processFilterExpressionInternal (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:227098)
at async tv.loadFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:231072)
at async tv.processFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:225690)
at async r.updateFilterExpression (app.chunk.uqm-firefly-app-chunk.28ed67de39470b4bd026.js:1:37154)
at async app.chunk.uqm-filter.c767e434c32c252c2cdd.js:1:13329

EDIT:
johnfeigs_0-1708968615056.png


In one of the charts tehre was this in a filter... which caused the error.
The script works neatly. Please feel free to use it to set a current date input control via script on initialization.



Accepted Solutions (1)

Accepted Solutions (1)

johnfeigs
Explorer
0 Kudos

Found the error in one of my charts:

johnfeigs_0-1708968497800.png

 

Answers (0)