Book a Demo

Author Topic: UTF-8 Javascript import to notes problem  (Read 6872 times)

nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
UTF-8 Javascript import to notes problem
« on: December 02, 2022, 11:13:50 pm »
Hi,
I'm trying to update the note field for components with text containing Swedish characters like ö ä å with a javascript.
I have them in an UTF-8 text file and have set the option "code page for source editing" to UTF-8

But when I import they get corrupted when importing into the notes field, works fine for import into tagged values.

Any ideas? Is there something special with the notes field?

Running v16.0.1604

Regards
Nils

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13471
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: UTF-8 Javascript import to notes problem
« Reply #1 on: December 02, 2022, 11:54:04 pm »
Someone reported a similar problem a few days ago.

Have you tried with the latest version (16.1.1622)?

Can you also post the code that you are using to update the notes, and how they get corrupted?

EA saves the notes in a xml like format in the database, so the "special" characters will get xml encoded.
They should look allright when viewing using the GUI

You might need to use the function Repository.GetFieldFromFormat (string Format, string Text) before saving to the notes.

Geert

nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #2 on: December 03, 2022, 12:05:51 am »
Hi,

The essential bit of the code
app = Repository.GetElementByGuid(sourceGUID);
app.Notes = applicationToCheck[15]; //array imported from a text file
app.Update();
app.Refresh();

The corruption is that the characters shows like a box with a question mark inside in Sparx and similar in Prolaborate

/N




nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #3 on: December 03, 2022, 12:18:39 am »
Hi,

And tested this but didn't work
app = Repository.GetElementByGuid(sourceGUID);
Xnote = Repository.GetFormatFromField("TXT", applicationToCheck[15]);
app.Notes = Xnote;
app.Update();
app.Refresh()

/N

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13471
  • Karma: +571/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: UTF-8 Javascript import to notes problem
« Reply #4 on: December 03, 2022, 12:21:45 am »
Hi,

And tested this but didn't work
app = Repository.GetElementByGuid(sourceGUID);
Xnote = Repository.GetFormatFromField("TXT", applicationToCheck[15]);
app.Notes = Xnote;
app.Update();
app.Refresh()

/N

Have you checked what get put into Xnote?
Does it work with the current version (or v15)?

Geert

PS. You can loose the call to Refresh()

nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #5 on: December 03, 2022, 12:36:31 am »
Hi,
Thanks for quick respons  :D
In debug Xnotes are just text and looks correct.
Seems like I need to test another version of Sparx and see if that is the problem.
During my tests I have seen some weird behavior that the text I import into tagged values also sometimes gets corrupted but with no apparent pattern when it happens.

Thanks for the call to Refresh() tip :-)

/Nils

nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #6 on: December 14, 2022, 06:28:42 pm »
Hi,
Just an update for those who are interested
It is the same problem in 15.2 and 16.1
/Nils

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #7 on: December 15, 2022, 08:16:29 am »
Xnote = Repository.GetFormatFromField("TXT", applicationToCheck[15]);
This call would be to take EA's internal notes format and write it as plain text. ie. The opposite of what you wanted.

Code: [Select]
Xnote = Repository.GetFieldFromFormat("TXT", applicationToCheck[i][15]);ie. You have plain text and you want to convert it to EA's internal format.

nilspc

  • EA User
  • **
  • Posts: 29
  • Karma: +1/-0
    • View Profile
Re: UTF-8 Javascript import to notes problem
« Reply #8 on: December 23, 2022, 07:20:31 pm »
Hi,
Thank you Eve
That solved the problem
/Nils