Create Tags with a variable name

Hi Guys,

I would like to create a tag based on the date (dd-mm-yyyy).
How do I structure the declare(“Tags.<variable_name>”) statement?

Regards,
DR

https://docs.genieacs.com/en/latest/provisions.html#tags

Thanks but I know how to create and remove Tags. What I need help with is to tag new devices with the date they first registered.
I am not sure how to write the declare statement with the Tag..

This information is already tracked by the ACS.

$ curl -i "https://localhost:7557/devices/?query=%7B%22_id%22%3A%22404A03-EX5510%252DB0-S220Z42004917%22%7D&projection=_registered"
HTTP/1.1 200 OK
GenieACS-Version: 1.2.13+240606fc80
Content-Type: application/json
total: 1
Date: Fri, 20 Sep 2024 16:35:20 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

[
{"_id":"404A03-EX5510%2DB0-S220Z42004917","_registered":"2023-03-03T23:40:00.085Z"}
]

Sorry for the late reply but I was on a short vacation.
Here is what I have now:

const firstInformDate = declare("Events.Registered", {value: 1}).value[0]
declare("Tags.test_"+firstInformDate, {value: Date.now()}, {value: true});

This creates the tag but not with the formated date “DD-MM-YYYY” but in seconds. For example the tag is created as test_1431308705117.

How can I format test_1431308705117 to the equivalent test_01-09-2023?
I tried .toString and a few others, without success.

GenieACS appears to expose the underlying EcmaScript Date object.

You can try this:

const d = declare("Events.Registered", {value: 1}).value[0]
const firstInformDate = d.getDate() + '_' + (d.getMonth() + 1) + '_' + d.getFullYear();

declare("Tags.test_"+firstInformDate, {value: Date.now()}, {value: true});

No guarantees on the code though. I haven’t tested it out.

I got an error:
TypeError: d.getDate is not a function

You can try this:

const d = new Date(declare("Events.Registered", {value: 1}).value[0]);

No guarantee it will work. If it doesn’t work, then you have three choices.

  • Accept that GenieACS does not have a full featured date library and you will not be able to accomplish your goal of creating a tag when a device is registered (still not sure why you want to do that)
  • Re-implement all the JS data stuff in a provision script. Not advisable
  • Call an external script where you can import date-fns/dayjs/momentjs/etc to convert a date in JS epoch format to a string

That worked.
Thanks very much for persisting.

DR