TM fields update: what's wrong?!

Hi everyone,

I have been pulling my hairs for two days on my part of the script which should set the TM fields update. My code is similar to the one of the SDK documentation but it seems that the field values are not stored in the projectsettings of my project.

Here is my code:

ISettingsBundle projSettings = newSDLProject.GetSettings();

TranslationMemorySettings projTMSettings = projSettings.GetSettingsGroup<TranslationMemorySettings>();

FileBasedTranslationMemory refTM = new FileBasedTranslationMemory(@"C:\Temp\RefTM.sdltm");

FieldValues tmFields = new FieldValues();

FieldDefinition fieldJobNo = refTM.FieldDefinitions["Doc. Code"];

FieldValue fvJob = fieldJobNo.CreateValue();

fvJob.Name = "139998";

            tmFields.Add(fvJob);

            projTMSettings.ProjectSettings.Value = tmFields;

            newSDLProject.UpdateSettings(projSettings);

This block of code is one part of a method where I create a project. I ran before or after having the project but it does not change anything. I am a bit lost and would be happy for some support.

Thanks in advance.

Regards,

Laurent

Parents
  • Could anyone help Laurent with this one?

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Hi everyone,

    I have implemented the following workaround to solve this problem: I set the value directly in the .sdlproj XML file after it has been created and save the file again:

    XmlDocument sdlProjXML = new XmlDocument();

               sdlProjXML.Load(newSDLProject.FilePath);

               XmlNodeList fieldValueNodes = sdlProjXML.GetElementsByTagName("FieldValue");

               foreach (XmlNode fvNode in fieldValueNodes)

               {

                       switch (fvNode["Name"].InnerText)

                       {

                           case "Doc. Code":

                               fvNode["Value"].RemoveAttribute("i:nil");

                               fvNode["Value"].InnerText = dsProjParams.Tables["StudioProjectParams"].Rows[0]["DocCode"].ToString();

                               break;

                           case "Job No.":

                               fvNode["Value"].RemoveAttribute("i:nil");

                               fvNode["Value"].InnerText = dsProjParams.Tables["StudioProjectParams"].Rows[0]["JobNo"].ToString();

                               break;

                       }

               }

               sdlProjXML.Save(newSDLProject.FilePath);

    However, this stays a workaround. So, if anyone has the solution using the API directly, please update this post.

    Regards,

    Laurent

Reply
  • Hi everyone,

    I have implemented the following workaround to solve this problem: I set the value directly in the .sdlproj XML file after it has been created and save the file again:

    XmlDocument sdlProjXML = new XmlDocument();

               sdlProjXML.Load(newSDLProject.FilePath);

               XmlNodeList fieldValueNodes = sdlProjXML.GetElementsByTagName("FieldValue");

               foreach (XmlNode fvNode in fieldValueNodes)

               {

                       switch (fvNode["Name"].InnerText)

                       {

                           case "Doc. Code":

                               fvNode["Value"].RemoveAttribute("i:nil");

                               fvNode["Value"].InnerText = dsProjParams.Tables["StudioProjectParams"].Rows[0]["DocCode"].ToString();

                               break;

                           case "Job No.":

                               fvNode["Value"].RemoveAttribute("i:nil");

                               fvNode["Value"].InnerText = dsProjParams.Tables["StudioProjectParams"].Rows[0]["JobNo"].ToString();

                               break;

                       }

               }

               sdlProjXML.Save(newSDLProject.FilePath);

    However, this stays a workaround. So, if anyone has the solution using the API directly, please update this post.

    Regards,

    Laurent

Children