# How to clear Date-Time Picker after each time it is used?

**URL:** <https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 12, 2023, 2:25am UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526 "2023-01-12T02:25:30Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 2:25am UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/1 "2023-01-12T02:25:30Z")

</div>

hi all  
I have been trying to reset the date time picker to default value after every use. I have set an expression to bind to enable tag of the "search product code " button . so that the button is only activated when it has a proper date and a tank count. So I have been trying to reset it to default. Can anyone help me with the script to make the date to a default value like null.

!

 ![manual_print](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/74de3cbee91e17d735ecf5c53b99198983101e5a.png)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 12, 2023, 2:41pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/2 "2023-01-12T14:41:22Z")

</div>

What is your binding on the value?

Use a script on your submit button and add a line at the end to set the value to `None` (Python's null) after the script is done.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 12, 2023, 5:29pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/3 "2023-01-12T17:29:46Z")

</div>

Agreed - a binding is not the way to go about this. At whatever point you deem the currently selected value of the picker to no longer be valid, you should just set the value of that picker to be None.

```auto
# this code lives in the onActionPerformed Event of the Submit button and assumes 
# that clicking the Submit button should also invalidate the picker, AND that the Submit button
# and picker are sibling components (same parent container)
self.getSibling("DateTimePicker").props.value = None

```

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/4 "2023-01-12T19:09:02Z")

</div>

I want the value of the date time picker to be stored in a memory tag , the binding is to a memory tag .  
But if you are using a confirm dialog box when u click on submit button. Can we use the null script on the yes button??

 ![confirm](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58e741a40610656176242321dd2bcf7e5347876e.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 12, 2023, 7:29pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/5 "2023-01-12T19:29:04Z")

</div>

There seems to be a disconnect here. Bindings should be used when you want something to always be synchronized with some other value. So if you bind your DateTime Picker (DTP) to a Tag value, you're essentially saying you want the DTP to always reflect the value of the Tag. If you _bi-directionally_ bind the DTP to the Tag, you're saying you want the DTP to reflect the Tag value AND UPDATE the Tag value when a user selects a different value.

BUT

You're also claiming you want the DTP to be cleared when a user "invalidates" the selected value by some beginning or completing some sequence of events. THIS seems more like a job for a change script in conjunction with logic to reset the DTP.

What I suggest is you provide a change script for the DTP:

```auto
# This will only write to the Tag when the value of the DTP is not None
if currentValue and currentValue.value is not None:
    system.tag.writeBlocking(["[provider]MyTagPath"],[currentValue.value])

```

Then, in your event sequence when you want to reset the value in the DTP, you can either do so via direct reference (previous example in a different post above), or - if the DTP is not a relative of the component being interacted with in the sequence - you can make use of Message Handling in Perspective.

Message "broadcast"/invocation:

```auto
# code to invoke on button press
system.perspective.sendMessage(messageType="ResetDTP", scope="page")

```

Mesasge listener (right-click DTP, select "Configure Scripts", double-click "Add handler...", supply a name of `ResetDTP`)

Within script of handler:

```auto
self.props.value = None

```

One additional note:  
All of this logic seems to be based on the value of a singular tag, but as you could potentially have multiple people using this process, it's likely you'll have users writing over each other to the tag because Tags are Gateway-scoped; you should consider moving away from suing a tag for this value in the first place unless you're comfortable with inter-session contention for reads/writes.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 12, 2023, 7:43pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/6 "2023-01-12T19:43:26Z")

</div>

It looks like you may be using a Require Confirm one-shot button. Is this the case?

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 7:46pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/7 "2023-01-12T19:46:05Z")

</div>

Actually, The date time picker is used to generate a barcode for the tanks being led into the furnace through a conveyor. The date the tank was manufactured is the first 8 characters of the barcode string. The operator at the conveyor will be using this view to generate any barcodes that are missing. Hence do you think the inter-session read/ write could affect the working?

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 7:47pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/8 "2023-01-12T19:47:37Z")

</div>

No, it is just an another view I created for a confirm dialog box, because the one shot button can only be reset by external mechanism.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 12, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/9 "2023-01-12T19:49:46Z")

</div>

In that case (assuming this is a general confirmation popup), you could use scripts as inputs to this popup and an output from the popup, dependent on if Yes or No is selected.

Use a custom tag on the view to hold the output from the popup and use an on-change script to reset your DTP value to `None`. Something along those lines.

It's difficult to say what exactly is going to work unless I try it for myself, but that would be my first thought.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 8:13pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/10 "2023-01-12T20:13:54Z")

</div>

the value from the DTP cannot be set to bi-directional when we are adding a change script to the DTP, I want the user to select the date and then it should update the tag. Also, can we set the date to todays date i,e. the current date to be set as the value of the DTP when the operator is using the view. So that it would be easier for the operator if he wants to generate a barcode of that date.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 12, 2023, 8:16pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/11 "2023-01-12T20:16:30Z")

</div>

To do this us an `onStartup` script on root container of the view.

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 12, 2023, 8:28pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/12 "2023-01-12T20:28:21Z")

</div>

Still not working

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 12, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/13 "2023-01-12T21:00:47Z")

</div>

This is how I would do it.

1. Create confirmation popup. Output from pop is `true` or `false` based on Yes or No reply. You'll have to message from the popup view to the calling view because popups have no way to reference outputs back to the view that called them ([post](https://forum.inductiveautomation.com/t/how-do-i-use-the-input-output-input-output-options-on-perspectives-view-params/24489/2)) You don't **have** to use message if you're okay with using the Confirm Dialog as an embedded view and toggle visibility, instead of using it as a popup.  

2. Add your submit button with a call to the confirm popup.

3. Add a message handler to the view's root container to receive the confirm message, write the tag, and reset the DTP.

```auto
def onMessageReceived(self, payload):
	# implement your handler here
	if payload['confirm']:
		date_to_write = self.getChild("DateTimePicker").props.value
		if date_to_write is not None:
			system.tag.writeBlocking()
		self.getChild("DateTimePicker").props.value = None

```

1. Add an onStartup script to the root container to set confirm to false and DTP to today's date. (this doesn't seem to work all the time, so maybe just provide another button to set to today instead of doing it on startup.)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/439eda600dd34708bb31ba7ee2fd6394b987e98c.png)

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 16, 2023, 11:57pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/14 "2023-01-16T23:57:03Z")

</div>

Any luck?  
I used part of your example on another solution:

> [@Read, write Tag values](https://forum.inductiveautomation.com/t/read-write-tag-values/68457/22):
>
> Start with just getting the output to change first. Then we'll worry about showing/hiding with the submit button. Make sure your parameters are set up correctly on your embedded view to get the output to change, rather than send a message. If this is the yes button script def runAction(self, event): if self.view.params.popup: system.perspective.sendMessage("Confirm", payload = {"payloadID":self.view.params.payload\_id, "confirm":True}) system.perspective.closePopup('') else: self.view.…

---

<div class="post-metadata">

**Author:** ![Bharat\_Krishnan](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Bharat\_Krishnan](https://forum.inductiveautomation.com/u/Bharat_Krishnan)\
**Post date:** [January 18, 2023, 3:58am UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/15 "2023-01-18T03:58:12Z")

</div>

Still not working.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [January 18, 2023, 9:07pm UTC](https://forum.inductiveautomation.com/t/how-to-clear-date-time-picker-after-each-time-it-is-used/68526/16 "2023-01-18T21:07:44Z")

</div>

Let's figure out exactly what isn't working.

Start by adding a simple "clear" button directly on the view with the DTP and use a script to set the DTP value to `None` (null). Does the DTP value go back to the default (blank)?

the button's onActionPerformed script should be:

```auto
def runAction(self, event):
	self.getSibling("DateTimePicker").props.value = None

```

Your DTP value **should not be bound** to anything, as you have shown in the first screenshot in your post.
