Book a Demo

Author Topic: Date format in element  (Read 8954 times)

ja1234

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Date format in element
« on: November 06, 2015, 08:30:25 pm »
Hi,

(JScript) I want to programatically add the created date to an element.

Code: [Select]
var currentDate = new Date();
element.Created = currentDate ;

triggers Typeconflict.

currentDate  has the value
Code: [Select]
Fri Nov 6 10:28:20 UTC+0100 2015
in which format should the date be such that I can insert it into the element?
« Last Edit: November 06, 2015, 08:30:59 pm by ja1234 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Date format in element
« Reply #1 on: November 06, 2015, 10:45:58 pm »
It's a Mickeysoft Variant object. I know how to create that in Perl and VB but not in JScript.

q.

ja1234

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Date format in element
« Reply #2 on: November 10, 2015, 07:40:42 pm »
The VB solution would be good also. Thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Date format in element
« Reply #3 on: November 10, 2015, 10:41:22 pm »
Ah. Now you got me.
Code: [Select]
currentElement.created = #2011-12-13#
currentElement.Update()
runs well, but it does not alter the creation day. I remember something that prevents (default) / allows altering of the creation date of objects. But I can't seem to find that back again in EA's options jungle  :(

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Date format in element
« Reply #4 on: November 10, 2015, 11:00:11 pm »
Well, although the documentation tells that Created is r/w it obviously isn't. The date-thingy was probably related with diagram (it's somewhere in the mist of memories). Anyhow, there's always another solution.
Code: [Select]
Repository.Execute("UPDATE t_object SET CreatedDate='01.01.2010 12:00:00' WHERE Object_ID = <theId>");where <theId> is that of the object. This will do.

q.
« Last Edit: November 10, 2015, 11:01:31 pm by qwerty »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Date format in element
« Reply #5 on: November 11, 2015, 08:57:53 am »
The option you're thinking of is at Tools > Options > Diagram > Allow change of Created Date
The Sparx Team
[email protected]

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Date format in element
« Reply #6 on: November 11, 2015, 10:00:37 am »
Yes, right. Any idea what about the CreateDate not changing despite the documentation?

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Date format in element
« Reply #7 on: November 12, 2015, 08:04:39 am »
The documentation is technically correct.

Read/Write means that a value can be assigned to that attribute. (vs assigning an value being an error at the compiler/interpreter level) It doesn't say what will happen to that attribute when you do.

It's the reverse of every single collection being documented as Read only. You can't change the object that is placed in that collection. It doesn't mean that you can't modify the object itself.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Date format in element
« Reply #8 on: November 12, 2015, 08:56:23 am »
Quote
The documentation is technically correct.
You mean like saying: the traffic light might take red color without explicitly telling you can be killed when crossing at red lights. You have a funny sort of humor :-X I guess everyone will understand r/w that writing will be saved on update.

To cite the help for Update()
Quote
Updates the current element object after modification or appending a new item.

Now one of both is wrong. Either Created is R/Don't Care or Update() does not save changes to Created.

Please correct that.

q.

P.S. The same applies to Modified. It also does not save the supplied value.
« Last Edit: November 12, 2015, 09:02:31 am by qwerty »

ja1234

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Date format in element
« Reply #9 on: November 13, 2015, 07:36:05 pm »
Quote
Well, although the documentation tells that Created is r/w it obviously isn't.

q.

Thanks q! This language independent solution that you suggested works. I was also confused as to why the element does not get updated, but as fallback to the direct database query, this does the job... Final code:

Code: [Select]
var el as EA.Element;
Repository.Execute("UPDATE t_object SET CreatedDate='01.01.2010 12:00:00' WHERE Object_ID = " + el.ElementID);

Result:


Was a lucky Friday 13 after all.   ::)

wikitect

  • EA User
  • **
  • Posts: 117
  • Karma: +2/-0
    • View Profile
    • TRAK Community
Re: Date format in element
« Reply #10 on: November 25, 2015, 01:01:45 am »
See also http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1447607897/0 wrt some circumstances under which the ModifiedDate for an element isn't updated (and also for connectors that have no metadata to capture creation or changes).
======
Favourite epitaph: 'Under this sod lies another'

TRAK Framework https://sf.net/p/trak
MDG for TRAK https://sf.net/p/mdgfortrak

ja1234

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Date format in element
« Reply #11 on: November 25, 2015, 01:45:21 am »
Quote
See also http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1447607897/0 wrt some circumstances under which the ModifiedDate for an element isn't updated (and also for connectors that have no metadata to capture creation or changes).
Thanks, this means I should remove the modified_date after all.. :o