Expire Date Event (v2021)

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
ahmed7
User
Posts: 97

Expire Date Event (v2021)

Post by ahmed7 »

Hello
I like to set value in one filed after date expire such as when current date comparation with date in field will be over so another field will changed automatically in list page without enter to edit page and change it.
Example :
end production date : 10/3/2023
current date :12/3/2023
will change production case field to "expired"

I hope to help me with this issue

thanks


darkdragon
User
Posts: 148

Post by darkdragon »

You better manage this directly in SQL. Have a job running each early morning to update the ProductionCase filed to expired.
e.g., something like:

update <table>
set ProductionCase = 'Expired'
where ProductionEndDate < getdate()

ahmed7
User
Posts: 97

Post by ahmed7 »

are there any way to do in asp.net maker?


darkdragon
User
Posts: 148

Post by darkdragon »

Not possible in ANM as you want "without enter to edit page and change it"
The data should be changed independently of users accessing the application or not, according to your requirements.


ahmed7
User
Posts: 97

Post by ahmed7 »

darkdragon wrote:

Not possible in ANM as you want "without enter to edit page and change
it"
The data should be changed independently of users accessing the application
or not, according to your requirements.
ok , if i do that by sql server , so i need to do this by query and execute it , and that need to execute it every time to get result , and that is the problem.
i need it be automatically .


darkdragon
User
Posts: 148

Post by darkdragon »

Is it possible to have new records with already expired production dates?

I do not get it why you want to have a continuous check?
If you run a job early on the morning (2:00AM, 3:00AM) you'll have all expired rows updated.

Is sounds like someone might add new records with already expired dates.


ahmed7
User
Posts: 97

Post by ahmed7 »

darkdragon wrote:

Is it possible to have new records with already expired production dates?

I do not get it why you want to have a continuous check?
If you run a job early on the morning (2:00AM, 3:00AM) you'll have all
expired rows updated.

Is sounds like someone might add new records with already expired dates.

OK , how to make query work daily without execute it by my self?


darkdragon
User
Posts: 148

Post by darkdragon »

in this case use triggers for both insert and update action, on your table.
here is an example of a trigger which runs after insert. you need to add one after update, in the case you have an Edit form, as well, where your date might change.

CREATE TRIGGER InsertProducts
ON dbo.Products
AFTER INSERT
AS
BEGIN
	UPDATE dbo.Products
	SET ProductionCase = 'Expired'
	WHERE ProductionEndDate < CurrentDate
	FROM dbo.Products p INNER JOIN INSERTED i ON p.ID = i.ID
END

of course you need to update your column names, accordingly.


ahmed7
User
Posts: 97

Post by ahmed7 »

Is (SQL Server Job Scheduler) will be useful instead of that way??
i think it will make query run in specific day and time ,


darkdragon
User
Posts: 148

Post by darkdragon »

As long as you do not allow an user to add new records with ProductionEndDate already expired, you're good to go with a job on SQL Agent (easier to manage)


ahmed7
User
Posts: 97

Post by ahmed7 »

darkdragon wrote:

As long as you do not allow an user to add new records with
ProductionEndDate already expired, you're good to go with a job on SQL
Agent (easier to manage)
I allow many users to add and edit but as you said " SQL Agent (easier to manage)"


Post Reply