NoahScheitler Posted September 29, 2023 Share Posted September 29, 2023 Im trying to make a .js text file to store a function within fusion pro. I want to then be able to simply call these functions out rather than copying files from older versions. I made one for a MatchCode that works currently it takes a 7 char string and returns the 5 rightmost chars. The second one im working on wont seem to work however. It should be returning the info for a datamatrix code, im wondering if its the MakeDataMatrixBarcode function within causing the issue. The first function that works is: function MatchCode(str) { str = Right(Field("Match"), 5); return str; } The function that doesnt work is: function datamatrix(str) { str = MakeDataMatrixBarcode(Field("Match"), true, "TEXT", 2, 3, false, "IDAutomationDMatrix"); return str; } Quote Link to comment Share on other sites More sharing options...
NoahScheitler Posted September 29, 2023 Author Share Posted September 29, 2023 3 hours ago, NoahScheitler said: Im trying to make a .js text file to store a function within fusion pro. I want to then be able to simply call these functions out rather than copying files from older versions. I made one for a MatchCode that works currently it takes a 7 char string and returns the 5 rightmost chars. The second one im working on wont seem to work however. It should be returning the info for a datamatrix code, im wondering if its the MakeDataMatrixBarcode function within causing the issue. The first function that works is: function MatchCode(str) { str = Right(Field("Match"), 5); return str; } The function that doesnt work is: function datamatrix(str) { str = MakeDataMatrixBarcode(Field("Match"), true, "TEXT", 2, 3, false, "IDAutomationDMatrix"); return str; } After messing around with this for a while i realized the function that makes MakeDataMatrixBarcode work is located in Builtins.js. So i copied the code for that and replaced the variables with my values and it works now. Here is the code for reference: function DataMatrixBarcode(ProcessTilde, EncodingMode, PreferredFormat, PointSize, NoFontTag, Font) { this.processTilde = true; this.encodingMode = "TEXT"; this.preferredFormat = 2; this.pointSize = 3; this.noFontTag = false; this.font = "IDAutomationDMatrix"; } //__________________________________________________________________ DataMatrixBarcode.prototype.Encode = function(DataToEncode) { return EncodeDataMatrixBarcode(Field("Match"), this.processTilde, this.encodingMode, this.preferredFormat); } DataMatrixBarcode.prototype.Make = function(DataToEncode) { var encoded = this.Encode(Field("Match"), this.processTilde, this.encodingMode, this.preferredFormat); var ReplacedBR = ReplaceSubstring(encoded, "\r\n", "<br>"); var ReplacedSpaces = ReplaceSubstring(ReplacedBR, " ", ""); if (!Int(this.pointSize)) return ReplacedSpaces; var WithPointSize = "<z newsize=\"" + Int(this.pointSize) + "\">" + "<leading newsize=\"" + Int(this.pointSize) * 10 + "\">" + ReplacedSpaces; if (this.noFontTag) return WithPointSize; var WithFontTag = "<f name=\"" + this.font + "\">" + WithPointSize; return WithFontTag; } function datamatrix(DataToEncode, ProcessTilde, EncodingMode, PreferredFormat, PointSize, NoFontTag, Font) { return new DataMatrixBarcode(ProcessTilde, EncodingMode, PreferredFormat, PointSize, NoFontTag, Font).Make(DataToEncode); } Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 2, 2023 Share Posted October 2, 2023 Can you be more specific about what's not working? I think all you need to do is this: function datamatrix() { var bc = new DataMatrixBarcode; bc.processTilde = true; bc.encodingMode = "TEXT"; bc.preferredFormat = 2; bc.pointSize = 3; bc.noFontTag = false; bc.font = "IDAutomationDMatrix"; return bc.Make(Field("Match")); } You don't need to re-create all the boilerplate DataMatrix code that's already in Builtins.js. Those functions and objects are designed so that you can set whatever properties you want in your own code that uses them. Also, note that you don't need to pass any parameter (such as "str") to these functions, since you're hard-coding the field value to use in there. You can just return the value you want. 1 Quote Link to comment Share on other sites More sharing options...
NoahScheitler Posted October 3, 2023 Author Share Posted October 3, 2023 19 hours ago, Dan Korn said: Can you be more specific about what's not working? Dan, After looking at it i think i was just misunderstanding how the syntax works here. It was just saying "Function does not return a value" when i validated it. I see what you are saying now though. I used your much simpler code and it worked just the same. I'm pretty new to javascript so i'm still trying to figure things out. Appreciate the help, Thanks! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.