Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Currently we have an acl script that adds the username to any comments that are inserted. There has been a request to add the date. Is there a way to only have the date? Under functions there is no date only option., only a time_date function.
function insert_tag_after_callback(doc, tagname, oid, op) {
if (op==1) { return 0; }
if (tagname == "_comment") {
goto_oid(oid);
insert("[" . time_date() . ", " . username() . "]: ");
}
}
doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");
Thanks
Bryon
Solved! Go to Solution.
Thanks to Gareth and PTC support for their help. The code below will give you the date and username output in a comment. If you want the time and date use the code in the first post. To add this to your environment, Create an acl file in the editinit folder and paste the code below into it.
function insert_tag_after_callback(doc, tagname, oid, op) {
if (op==1) { return 0; }
if (tagname == "_comment") {
goto_oid(oid);
insert("[".substr(time_date(),1,10).", ".substr(time_date(),21,4).",".username()."]:")
$x=substr(time_date(),1,10);gsub(" "," ",$x)
}
}
doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");
You might have to do a little work to get the date in the format you need, e.g., the docs say that time_date() produces something like "Mon Dec 28 17:23:52 1992". You want to fish out the "Dec 28" part and the year, I'm guessing?
You can use one of the regular expression functions to do the string manipulation - sub() or match() are probably most helpful here. With sub() you can clear out the bits of the text you don't want.
text = time_date()
sub(/^.* /, "", text)
I haven't tested, but something like the above would clear the day name out from the string, and you could keep going to clear the timestamp too.
Thanks to Gareth and PTC support for their help. The code below will give you the date and username output in a comment. If you want the time and date use the code in the first post. To add this to your environment, Create an acl file in the editinit folder and paste the code below into it.
function insert_tag_after_callback(doc, tagname, oid, op) {
if (op==1) { return 0; }
if (tagname == "_comment") {
goto_oid(oid);
insert("[".substr(time_date(),1,10).", ".substr(time_date(),21,4).",".username()."]:")
$x=substr(time_date(),1,10);gsub(" "," ",$x)
}
}
doc_add_callback(0, "insert_tag_after", "insert_tag_after_callback");