Maxime Grazzini Posted July 12, 2017 Share Posted July 12, 2017 Hello guys, pretty new to spotfire scripting API. Code here : import Spotfire.Dxp.Application.Filters as filters import Spotfire.Dxp.Application.Filters.ListBoxFilter import time from datetime import datetime, timedelta, date from Spotfire.Dxp.Application.Filters import FilterTypeIdentifiers from Spotfire.Dxp.Data import * from Spotfire.Dxp.Application.Filters import * from Spotfire.Dxp.Data.DataType import Date f = open("C:\Users\ng6ce1f\Documents\TEST.txt", 'w', 0) #Get Filter page filterPanel = dataPage.FilterPanel #Get all filters we wish to adjust, and adapt them if needed (from a range to checkbox for example) #Getfilter return a filterReference, so we have to set his type and then get the filter using filterName.FilterReference.As[TypeFilter]() (which cast the filter so python knows we can acces specific methods) msnFilterReference = filterPanel.TableGroups[0].GetFilter("MSN") msnFilterReference.FilterReference.TypeId = FilterTypeIdentifiers.RangeFilter msnFilter = msnFilterReference.FilterReference.As[RangeFilter]() handoverDateFilterReference = filterPanel.TableGroups[0].GetFilter("MSN Handover date") handoverDateFilterReference.FilterReference.TypeId = FilterTypeIdentifiers.RangeFilter handoverDateFilter = handoverDateFilterReference.FilterReference.As[RangeFilter]() deliverDateFilterReference = filterPanel.TableGroups[0].GetFilter("MSN Indus Delivery date") deliverDateFilterReference.FilterReference.TypeId = FilterTypeIdentifiers.RangeFilter deliveryDateFilter = deliverDateFilterReference.FilterReference.As[RangeFilter]() #Get properties in our Filter page selectedMSN = Document.Properties["MSNSelect"] selectedHandoverDate = Document.Properties["HandoverDateSelected"] selectedDeliveryDate = Document.Properties["DeliveryDateSelected"] #Depending on the chosen properties, we adjust our filters accordingly #Set msn filter if selectedMSN == "7000More": msnFilter.ValueRange = ValueRange(7000,msnFilter.ValueRange.High) elif selectedMSN == "7000Less": msnFilter.ValueRange = ValueRange(msnFilter.ValueRange.Low,6999) else: msnFilter.ValueRange = ValueRange(msnFilter.ValueRange.Low, msnFilter.ValueRange.High) #Set Handover date filter currentDate = Date.Formatter.Parse(time.strftime("%d/%m/%Y")) if selectedHandoverDate == "PastHandover": handoverDateFilter.ValueRange = ValueRange(handoverDateFilter.ValueRange.Low ,currentDate) elif selectedHandoverDate == "FuturHandover": handoverDateFilter.ValueRange = ValueRange(currentDate,handoverDateFilter.ValueRange.High) else: handoverDateFilter.ValueRange = ValueRange(handoverDateFilter.ValueRange.Low,handoverDateFilter.ValueRange.High) #Set Delivery date filter dateTimePlusWeek = datetime.today() + timedelta(days=7) datePlusWeek = dateTimePlusWeek.date() if selectedDeliveryDate == "DeliveryNextWeek": deliveryDateFilter.ValueRange = ValueRange(deliveryDateFilter.ValueRange.Low ,datePlusWeek) else: f.write("else") deliveryDateFilter.ValueRange = ValueRange(deliveryDateFilter.ValueRange.Low,deliveryDateFilter.ValueRange.High) f.close() #Goto Data page Document.ActivePageReference=dataPage What is interesting here is : #Set Delivery date filter dateTimePlusWeek = datetime.today() + timedelta(days=7) datePlusWeek = dateTimePlusWeek.date() if selectedDeliveryDate == "DeliveryNextWeek": deliveryDateFilter.ValueRange = ValueRange(deliveryDateFilter.ValueRange.Low ,datePlusWeek) I have a dateRange filter that I got earlier, and I want to set my date to Today + 7 days, then set the filter using this new date. Problem is, nothing is changing, and no error. I don't understand because I also use a datetime for the previous filter setting and it works perfectly, but here it does not. Would you have any idea why Thank you. EDIT : After some research, if I usedatetime.today() instead ofDate.Formatter.Parse(time.strftime("%d/%m/%Y")) in theSet Handover date filter, it stops working too. So now I'm looking for a way to get a date seven days from now using something likeDate.Formatter.Parse(time.strftime("%d/%m/%Y")) Link to comment Share on other sites More sharing options...
Sayali Patil Posted July 19, 2017 Share Posted July 19, 2017 Hello, If you share a sample dxp with the python script that fails, it would be easier to help.Without a dataset to look at its hard to suggest something! Link to comment Share on other sites More sharing options...
Federico Verrastro Posted February 19, 2020 Share Posted February 19, 2020 Have you tried: dateTimePlusWeek = datetime.today().AddDays(7) or even: dateTimePlusWeek = datetime.today() dateTimePlusWeek =dateTimePlusWeek.AddDays(7) Hope it helps, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now