Automatic Calculation of Time Remaining How do I make a new column

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Sep 29, 2016
Company: ELPO BILISIM OTOMASYON ELEKTRONIK LTD.

Beforewrite did with the method, but not the way I want

How do I write to autorefresh method ? Or How do I make ?

Edited: Mehmet Ali KOÇAK - Oct 04, 2016 12:14 AM
 
#2
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Jun 10, 2016
Company:

Can you use ConditionalAppearance property of form?

Edited: Sergey Blagoveshchenskiy - Oct 03, 2016 09:15 AM
 
#3
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Apr 18, 2012
Company:

Hi Mehmet!

It's hard to say what works wrong in your code.
I advise to use function Int() instead Number(Format()).
Also you can use debugger for finding trouble.

I wrote similar code, it works

Code
Minutes = Int((ThisObject.AttributeDate - CurrentDate()) / 60);
If Minutes < 0 Then
   ThisObject.AttributeString = "OK";
EndIf;

Edited: Alexei Khatin - Oct 03, 2016 02:09 PM
 
#4
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Sep 29, 2016
Company: ELPO BILISIM OTOMASYON ELEKTRONIK LTD.

Hi!
Alexei Khatin,

I was working Codes but,I want continuous calculation of the remaining time

PresentationGetProcessing() method not set field KalanSüre
how do make it

 
#5
People who like this:1Yes/0No
Active user
Rating: 4
Joined: Apr 18, 2012
Company:

Hi, Mehmet.

I suggest the most easiest solution, that I could find.

1. Create information register "RemainingTime"

2. Check flag "Custom Query" in the list form of the document

3. Open "list setup" (hyperlink under checkbox) and modify query text

4. Put new column "Time" on the form

5. Create scheduled task for filling register "RemainingTime"
Check flags "Use" and "Predefined" for scheduled task
Setup schedule: Perform: every  day; every 60 second
Check flags "Server" and "Plivileged" for common module "ScheduledJobsServer"

Code of the task:

Code
Procedure UpdateRemainingTime() Export
   Now = CurrentDate();
   Query = New Query;
   Query.Text = 
   "SELECT
   |   Document3.Ref,
   |   Document3.AttributeDate
   |FROM
   |   Document.Document3 AS Document3
   |WHERE
   |   Document3.AttributeDate > &CurrentDate";
   
   Query.SetParameter("CurrentDate", Now);
   
   QueryResult = Query.Execute().Select();
   
   RecordSet = InformationRegisters.RemainingTime.CreateRecordSet();
   While QueryResult.Next() Do
      Record = RecordSet.Add();
      Record.Document = QueryResult.Ref;
      Record.Time = GetRemainingTimeText(QueryResult.AttributeDate, Now)
   EndDo;
   RecordSet.Write();
EndProcedure

Function GetRemainingTimeText(AttributeDate, Now) Export
   Minutes = Int((AttributeDate - Now) / 60);
   Hours = Int(Minutes / 60);
   Days = Int(Hours / 24);
   
   Minutes = Minutes - 60 * Hours;
   Hours = Hours - 24 * Days;
   
   Result = "";
   If Days > 0 Then
      Result = Result + " " + Days + " days"
   EndIf;
   If Hours > 0 Then
      Result = Result + " " + Hours + " hours"
   EndIf;
   If Minutes > 0 Then
      Result = Result + " " + Minutes + " minutes"
   EndIf;
   Result = Result + " left";
   
   Return Result;
EndFunction


Note, in file mode tasks start two minutes after session start.

6. Enjoy result

7. Also you can add this code in the document's module for instant upd ate when you save document
Code
Procedure OnWrite(Cancel)
   RecordSet = InformationRegisters.RemainingTime.CreateRecordSet();
   RecordSet.Filter.Document.Set(Ref);
   Now = CurrentDate();
   If AttributeDate > Now Then
      Record = RecordSet.Add();
      Record.Document = Ref;
      Record.Time = ScheduledJobsServer.GetRemainingTimeText(AttributeDate, Now)
   EndIf;
   RecordSe t.Write();
EndProcedure

Download 1.png (43.44 KB)
Download 2.png (110.7 KB)
Download 3.png (21.63 KB)
Download 5.png (8.59 KB)
Download 6.png (4.16 KB)
Edited: Alexei Khatin - Oct 04, 2016 05:34 AM
 
#6
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Apr 18, 2012
Company:

In version 8.3.10 will be new functionality and it would be much easier to solve this problem

Here is a link, if you can understand something in Russian.
<the links should open pages in English>

 
#7
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Sep 29, 2016
Company: ELPO BILISIM OTOMASYON ELEKTRONIK LTD.

Alexei Khatin,

thank you, I worked apply the method

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.