Friday, February 25, 2011

Export and import Dynamics Ax labels

static void ExportLabels(Args _args)
{
str module = "TUS";
str exportFile = "\\\\tsclient\\c\\fil1.txt";
Label l;
str s;
int i;
System.IO.TextWriter tw;
;
l = new Label();
i = 0;
tw = new System.IO.StreamWriter(exportFile);
while(i < 9999)
{
s = l.extractString("@" + module + int2str(i));
if(substr(s,1,1) != '@')
tw.WriteLine("@" + module + int2str(i) + ";" + s);
i++;
}
tw.Close();
}

static void ImportLabels(Args _args)
{
str module = "TUS";
str importFile = "\\\\tsclient\\c\\fil2.txt";
Label l;
str s;
System.IO.TextReader tw;
System.String ss;
str labelid, labeltext;
int i;
str existingLabel;
;
l = new Label();
tw = new System.IO.StreamReader(importFile);
ss = tw.ReadLine();
while(ss)
{
s = ss;
i = strScan(s, ";", 1, 10);
if(i > 0)
{
labelid = substr(s, 1, i - 1);
labeltext = substr(s,i + 1,strlen(s) - i + 1);

existingLabel = l.extractString(labelid);
if(substr(existingLabel,1,1) == '@')
{
l.insert(labeltext,"",module);
}
else
{
if(existingLabel != labeltext)
info("Existing label " + labelid + ", Old value = " + existingLabel + ", New value = " + labeltext);
}
}
ss = tw.ReadLine();
}
tw.Close();
}

1 comment:

Anonymous said...

That's great. Thank you very much!