MHardee Posted October 31, 2008 Share Posted October 31, 2008 OK, with much help from several folks here I've gotten this to work on a Mac.. sort of.... Basically, original data has 168 records, with a quantity field that should produce 499 records in the "New" data file generated from the OnJobStart rule. I can NOT get it to work on a server, can get it to at least create the "new" file locally on the Desktop of my Mac. BUT... The new data file that is created skips the first 10 records, and results in 1117 records one time and 0 records the next time.. very inconsistent... My assumptions: 1. Java CAN count? 2. The Newly generated datafile is read in at composition time? (not working as of yet).. When exactly is the new file generated - so far, I can get it to be created by editing the rule and validating.. sometimes it returns 0? One run: /users/Digimac2/Desktop/17342-D/Data/17342_DATA.txt 168 records /users/Digimac2/Desktop/17342-D/Data/17342_DATA_New.txt 0 records ANY help would be appreciated - I am getting very close, I feel... Link to comment Share on other sites More sharing options...
Dan Korn Posted October 31, 2008 Share Posted October 31, 2008 I assume you're talking about the repeat a record workaround. Can you post the JavaScript logic you're using? I don't see how anyone is going to be able to help you without it. Have you looked at this? http://forums.printable.com/showpost.php?p=46&postcount=2 My assumptions: 1. Java CAN count? I don't know about Java, but JavaScript can indeed count. (Sorry, I have a pet peeve about mixing up the names of these two different programming languages.) The problem is somewhere in your code. But I'd have to see the code to be able to figure out what's wrong. 2. The Newly generated datafile is read in at composition time? (not working as of yet).. Again, that depends on what your JavaScript logic is doing. Link to comment Share on other sites More sharing options...
MHardee Posted October 31, 2008 Author Share Posted October 31, 2008 Have you looked at this? http://forums.printable.com/showpost.php?p=46&postcount=2 Yes, that's where I started... I don't know about Java, but JavaScript can indeed count. (Sorry, I have a pet peeve about mixing up the names of these two different programming languages.) As SOON as I hit the send button, I had that "Java versus Javascript" flashback, sorry! The problem is somewhere in your code. But I'd have to see the code to be able to figure out what's wrong. Currently: (data attached as well).. I appreciate the help.. I am really trying to get this working - been on it off and on for three-four months.. // OnJobStart rule to repeat records var RepeatFieldName = Int(Field("Quantity")); // EDIT THIS //return RepeatFieldName var FieldDelimiter = "\t"; // EDIT THIS ("\t" for tab-delimited) var orginputfilename = FusionPro.Composition.inputFileName; // For composition, the original name is set, // and the new name must be specified as an HFS path on Mac. // EDIT THIS var newfilename = "Macintosh HD:users:Digimac2:Desktop:17342-D:Data:17342_DATA_GEN.txt"; //return newfilename if (FusionPro.inValidation) { // For composition, both names must be specifiesd as POSIX paths on Mac. // EDIT THIS orginputfilename = "/users/Digimac2/Desktop/17342-D/Data/17342_DATA.txt"; //return orginputfilename // EDIT THIS newfilename = "/users/Digimac2/Desktop/17342-D/Data/17342_DATA_GEN.txt"; //return newfilename } // DO NOT EDIT BELOW THIS LINE var sf = new ExternalDataFileEx(orginputfilename, FieldDelimiter); if (!sf.valid) throw("Unable to open ExternalDataFile: " + orginputfilename); var of = new File(newfilename); //of.remove(); if (of.open("create") == false) throw("Could not create output file."); of.close(); if (of.open("write") == false) throw("Could not write output file."); for (var i=0;i<sf.fieldCount;i++) { if (i) of.write(FieldDelimiter); of.write(sf.GetFieldValue(0, i)); } of.write("\r\n"); var NewInputTotalRecords = 0; for (var i = 0 ; i <= sf.recordCount; i++) { var startval = 1; //return startval var repeatcount = Int(sf.GetFieldValue(i, RepeatFieldName)); //return repeatcount for(var j = 0; j < repeatcount; j++) { NewInputTotalRecords++; for(var k = 0; k < sf.fieldCount; k++) { if (k) of.write(FieldDelimiter); switch(sf.GetFieldValue(0, k)) { case RepeatFieldName: of.write(startval+j); break; default: of.write(sf.GetFieldValue(i, k)); } } of.write("\r\n"); } } of.close(); FusionPro.Composition.inputFileName = newfilename; var message = orginputfilename + "\n" + sf.recordCount + " records\n\n"; message += FusionPro.Composition.inputFileName + "\n" + NewInputTotalRecords + " records"; Print(message); return message; Link to comment Share on other sites More sharing options...
Dan Korn Posted October 31, 2008 Share Posted October 31, 2008 As SOON as I hit the send button, I had that "Java versus Javascript" flashback, sorry! No problem. But it's JavaScript, with a capital "S". Currently: (data attached as well).. I appreciate the help.. I am really trying to get this working - been on it off and on for three-four months.. Okay, first of all, here's a tip for posting code in the forum: Put it in [noparse][/noparse] blocks. You can have the editor do this automatically by selecting the code and clicking the # button above the editor. (You may need to click the "Go Advanced" button first if you're in "Quick Reply" mode.) This will keep the formatting correct, and prevent vBulletin silliness like converting [noparse][/noparse] into a smiley face. (In case you're wondering how I prevented the smiley face in the previous sentence, it was by using [noparse][noparse] and [/noparse][/noparse] tags.) I've done this with your code below. // OnJobStart rule to repeat records var RepeatFieldName = Int(Field("Quantity")); // EDIT THIS //return RepeatFieldName var FieldDelimiter = "\t"; // EDIT THIS ("\t" for tab-delimited) var orginputfilename = FusionPro.Composition.inputFileName; // For composition, the original name is set, // and the new name must be specified as an HFS path on Mac. // EDIT THIS var newfilename = "Macintosh HD:users:Digimac2:Desktop:17342-D:Data:17342_DATA_GEN.txt"; //return newfilename if (FusionPro.inValidation) { // For composition, both names must be specifiesd as POSIX paths on Mac. // EDIT THIS orginputfilename = "/users/Digimac2/Desktop/17342-D/Data/17342_DATA.txt"; //return orginputfilename // EDIT THIS newfilename = "/users/Digimac2/Desktop/17342-D/Data/17342_DATA_GEN.txt"; //return newfilename } // DO NOT EDIT BELOW THIS LINE var sf = new ExternalDataFileEx(orginputfilename, FieldDelimiter); if (!sf.valid) throw("Unable to open ExternalDataFile: " + orginputfilename); var of = new File(newfilename); //of.remove(); if (of.open("create") == false) throw("Could not create output file."); of.close(); if (of.open("write") == false) throw("Could not write output file."); for (var i=0;i<sf.fieldCount;i++) { if (i) of.write(FieldDelimiter); of.write(sf.GetFieldValue(0, i)); } of.write("\r\n"); var NewInputTotalRecords = 0; for (var i = 0 ; i <= sf.recordCount; i++) { var startval = 1; //return startval var repeatcount = Int(sf.GetFieldValue(i, RepeatFieldName)); //return repeatcount for(var j = 0; j < repeatcount; j++) { NewInputTotalRecords++; for(var k = 0; k < sf.fieldCount; k++) { if (k) of.write(FieldDelimiter); switch(sf.GetFieldValue(0, k)) { case RepeatFieldName: of.write(startval+j); break; default: of.write(sf.GetFieldValue(i, k)); } } of.write("\r\n"); } } of.close(); FusionPro.Composition.inputFileName = newfilename; var message = orginputfilename + "\n" + sf.recordCount + " records\n\n"; message += FusionPro.Composition.inputFileName + "\n" + NewInputTotalRecords + " records"; Print(message); return message; Another thing I've noticed is that for some reason, if you copy-and-paste code directly from the Rule Editor into the vBulletin forum message box, it will remove any indentation at the beginnings of lines, which makes the code harder to follow. (I'm looking into ways to prevent this from both ends, FusionPro and vBulletin.) My workaround is to first copy-and-paste into a text-only editor such as Notepad or BBEdit and then copy-and-paste from there into the forum. Anyway, that said, now we can examine your code and try to figure out where it's going wrong. If I put your code side-by-side with my code from that other post, the first thing I notice is the very first line (after the initial comment. I have: var RepeatFieldName = "Repeat Count"; // EDIT THIS And you have: var RepeatFieldName = Int(Field("Quantity")); // EDIT THIS So that's where I would start. You may just want to start over from the rule I posted and replace your field and file names and such. Remember not to modify anything below where it say, "DO NOT EDIT BELOW THIS LINE." Link to comment Share on other sites More sharing options...
MHardee Posted October 31, 2008 Author Share Posted October 31, 2008 I've done this with your code below. var RepeatFieldName = "Repeat Count"; // EDIT THISAnd you have: var RepeatFieldName = Int(Field("Quantity")); // EDIT THISSo that's where I would start. You may just want to start over from the rule I posted and replace your field and file names and such. Remember not to modify anything below where it say, "DO NOT EDIT BELOW THIS LINE." I will look at it again.. The code example above, I assumed (and you know what they say about ASSuming, that a fieldname would be inserted there like most other rules I've used. i.e., Field(Fieldname).. I changed that to just "Fieldname" and it now seems to verify the correct number of generated records, but, appears to lock up when composing... I've been staring at the attached image for fifteen minutes now.. Link to comment Share on other sites More sharing options...
Dan Korn Posted October 31, 2008 Share Posted October 31, 2008 I will look at it again.. The code example above, I assumed (and you know what they say about ASSuming, that a fieldname would be inserted there like most other rules I've used. i.e., Field(Fieldname).. I changed that to just "Fieldname" and it now seems to verify the correct number of generated records, but, appears to lock up when composing... I've been staring at the attached image for fifteen minutes now.. I can't really see much in the tiny picture you attached, but if the composition is hung up, it's time to do some debugging. I would start liberally adding some Print function calls into the rule so that you can track what's going on from the log file messages. You can always add a return statement somewhere else in the rule to short-circuit it and make sure you've gotten to a partcular point, then move the return statement farther down and try again, until you can isolate where the hangup is occurring. (Yes, it's time to edit below the line that says you shouldn't edit below it.) You might want to start by doing something like this right after the line where the repeatcount variable is declared: Print("record " + i + ", repeat count " + repeatcount); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.