This latest problem has been driving me nuts for several days now!

I thought using this in the DHTML version would be easier as it uses HTML and javascript but no such luck so far. I have put this code in my "sharedActions" XML file.
- Code: Select all
<function name="createDistributionCode" event="" params="">
<![CDATA[
var mySchool = this.myArray[4];
var exName = this.myArray[2];
var A = tbfunction_pgExecuteRemote("response", "encryptMyText", mySchool + ",someKey");
var codeKey;
if (mySchool.length > 4)
{
var ADetail = [];
ADetail = Array.from(mySchool);
codeKey = ADetail[3] + ADetail[4] + ADetail[1] + ADetail[0] + ADetail[2];
}
else
{
codeKey = "anotherKey";
}
var B = tbfunction_pgExecuteRemote("response", "encryptMyText", exName + "," + codeKey);
if (exName.length > 3)
{
codeKey = exName.substring(0, 4);
}
else
{
var BDetail = [];
BDetail = Array.from(exName);
codeKey = BDetail[0] + "N" + BDetail[0] + "a";
}
var C = tbfunction_pgExecuteRemote("response", "encryptMyText", exName + "," + codeKey);
var returnValue = "***§" + A + "§" + B + "§" + C;
//Here returnValue is always incorrect as it contains line breaks!!
returnValue = tbfunction_pgReplace("/^\s+|\s+$/", "", returnValue, true);
returnValue = tbfunction_pgReplace("\n", "", returnValue, true);
alert(returnValue); //The value alerted here has always been correct!!
tbfunction_pgTBObjSet("codeBar", "text", returnValue); //This has sometimes worked but is not reliable!!
// return returnValue This has never worked!!
]]>
</function>
The problem is getting the encypted strings from the XML function to the Toolbook part of the program intact. If I use return to send them they always arrive corrupted. There are spaces and characters missing which renders them useless. It's slightly better if I use pgTBObjectSet to put them into the text of a TB field but this is also unreliable. I have tried putting the 3 codes into an array but this fails. I have also tried writing the string to a cookie but the string is never written correctly. However if I use the alert in the code above to manually copy the code and paste it into the destination file it always works.
Here is a picture of what I get before the 2 pgReplace lines.

And here is a picture of a correct result after the 2 pgReplace lines.

Unfortunately even if I repeat the pgReplace lines in the subsequent TB actions sequence I rarely get the desired result although it must be said that from time to time it works!
What can I do to make sure the strings arrive intact so that I can write them into the file correctly? I'd be most grateful if you have any suggestions. Thanks for your time.
John