Hello,
I am grappling with a seemingly straightforward issue. I am utilizing the Month Picker component from Outsystems UI, but I cannot figure out how to set the initial month to the current month.
The InitialMonth variable is of the MonthYear type, and when I expand it, the Month variable appears to have a Month Identifier type. I presume this type expects the full name of the month, which means that using something like Month(CurrDate()) would not work.
I came across a discussion where it was mentioned that this issue was resolved in OS UI 2.13 (ROU-3951). I am currently using version 2.16, however, the release notes for that fix indicate an improvement to the Month Picker component such that it returns the month order when the OnSelect event is activated, which doesn't seem to address the original issue raised in the topic I referred to.
Has anyone managed to find a solution to this?
Hi @Andrea Caselli ,
That option wasn’t added on the Input Parameter’s for two reasons:
That being said, I attached an oml with two solutions. One using a more low-code approach and another one using the Initialized event of the MonthPicker, with the OutSystems UI JS API.
Let me know if it helped!
Best regards,
Bernardo Cardoso
Hey Andrea,
You have to follow the below steps
1)create one value called currentMonth of type Month Identifier
2)Create onInitialize and use the switch like below image and assign the months
3)use the currentMonth Varible in your month
It will work!
Thanks & Regards,
Sudip Pal
Hi @Sudip Pal ,
Thank you for your guidance!
I had considered this approach, albeit as a last resort. It strikes me as quite cumbersome – is this genuinely the only method to accomplish this?
I'm contemplating proposing a new "Idea": a built-in function named "Month" that would yield an output of the "Month Identifier" type. This could potentially streamline the process considerably.
Hey @Andrea Caselli ,
Use the following code in place of month :
If(Month(CurrDate())=1,Entities.Month.January,If(Month(CurrDate())=2,Entities.Month.February,If(Month(CurrDate())=3,Entities.Month.March,If(Month(CurrDate())=4,Entities.Month.April,If(Month(CurrDate())=5,Entities.Month.May,If(Month(CurrDate())=6,Entities.Month.June,If(Month(CurrDate())=7,Entities.Month.July,If(Month(CurrDate())=8,Entities.Month.August,If(Month(CurrDate())=9,Entities.Month.September,If(Month(CurrDate())=10,Entities.Month.October,If(Month(CurrDate())=11,Entities.Month.November,Entities.Month.December)))))))))))
It will definitely work!!!
Hey Andrea Caselli,
When you want: "Set Initial Month to current month in Month Picker component", what is your objective?
Would it be that when the screen is opened, the Month Picker will be selected with the Current Month?
- If this is your objective, simply:
1) Create a variable on the screen called: "DataSelected", type Date,
where we will have its initial value with Current Month/Year. And, after a new selection, it will save the Month/Year that was selected.
2) In the "OnInitialize" screen, put an "Assign" with: DataSelected = NewDate(Year(CurrDate()), Month(CurrDate()), 1)
3) In the MonthPicker "Input", put variable = DataSelected .
4) In the MonthPickerOnSelected action, put an "Assign": DataSelected = NewDate(SelectedMonth.Year,SelectedMonth.MonthOrder,1)