Author Topic: Question: how to set variables in Label Expression  (Read 202 times)

xiaoqi

  • Active Member
  • ***
  • Posts: 61
  • Today is the Tomorrow we talked about Yesterday
Question: how to set variables in Label Expression
« on: May 12, 2021, 03:25:26 AM »
Hello,

Just new to using jArchi.

Searched on our jArchi wiki and forum here, not found the direct same question, so put a new here to seek your advice.

I'm using Archi to create lots of views, each view I give a View Name which I'm using Label Expression as $view{name} so that it's automatically link to the name I give to the view, this works fine as it's get from our pre-defined attribute.

While I'd also have another label willing to show the date I'm keep updating the view, e.g. "Updated at 2011/05/11", but I'd like this date can be having a way to fill in by script, no need to manually key in the data every time. (while, no need to keep refreshing that, so I'm thinking if there's a script that I can run and apply to the selected Label, and fill in the format in "Updated at yyyy/mm/dd" and the data is current date, that would be sufficient.)

I create one simple script as below:

Code: [Select]
/*
 * Objective: add Label to a view, and able to run and refresh the label text to the formate "updated at 2021/05/11", in which 2011/05/11 is the current date
 */
 
current_datetime = new Date();
formatted_date = "Updated at " + current_datetime.getFullYear() + "/" + (current_datetime.getMonth() + 1) + "/" + current_datetime.getDate();

console.log(formatted_date);

The script is OK of running and can display in console. But is there any method that I can link to the selected label? Maybe there's some attributes that I should use to call from this script, so when I select the blank label, I can execute the script and it's filled the line of text from code.

Thanks a lot,
Xiaoqi

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 695
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: Question: how to set variables in Label Expression
« Reply #1 on: May 12, 2021, 07:02:00 AM »
Hi,

I have something very similar. I'm using a property ("Last Update") attached to the view and references this property from the note's label ($view{property:Last Update}).

Then it's easy to update the view's property from a script (just make sure you selected the view before running the script).

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

xiaoqi

  • Active Member
  • ***
  • Posts: 61
  • Today is the Tomorrow we talked about Yesterday
Re: Question: how to set variables in Label Expression
« Reply #2 on: May 13, 2021, 02:58:02 AM »
Hi JB,

Thanks a lot, it's really simple way and working.

Following is the updaated script to deal with that "Last Update" property in the View:

Code: [Select]
current_datetime = new Date();
formatted_date = "Updated at " + current_datetime.getFullYear() + "/" + (current_datetime.getMonth() + 1) + "/" + current_datetime.getDate();

$(selection).prop("Last Update", formatted_date);

console.log(formatted_date);

Have a nice day,
Xiaoiq