Fellsway Posted November 6, 2012 Share Posted November 6, 2012 Is there a way for FusionPro to search through multiple fields (over 100 fields) and do a text replacement? Example: Find the word "blank" and replace with a space instead. Quote Link to comment Share on other sites More sharing options...
esmith Posted November 6, 2012 Share Posted November 6, 2012 How are you trying to use that functionality? You can change values before using them on your template, but you can not edit the attached data file from within FP. You'd be better off to do that "upstream" in a spreadsheet/text editor app. Quote Link to comment Share on other sites More sharing options...
Fellsway Posted November 6, 2012 Author Share Posted November 6, 2012 Yes, I am trying to change values before using them on my template. I don't want to edit my data file. I was thinking that a Onjobstart rule would work for this situation. Quote Link to comment Share on other sites More sharing options...
esmith Posted November 6, 2012 Share Posted November 6, 2012 You still haven't indicated what you are trying to accomplish, but if you just want to convert values per record in a callback rule, that's certainly possible. OnRecordStart rule: noBlanks = []; // don't use 'var' to make array global var totalFields = 100; //enter the number of fields to check var startField = 1; // enter which field to begin with for (var s=0; s<totalFields; s++) { noBlanks[s] = Field(s+startField).replace(/blank/g," "); } Then pull from the array rather than the field in your data for the corrected value. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 6, 2012 Share Posted November 6, 2012 Is there a way for FusionPro to search through multiple fields (over 100 fields) and do a text replacement? Example: Find the word "blank" and replace with a space instead. Sure, do this in OnRecordStart: for (var i in FusionPro.Fields) FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "blank", " "));Note that this replaces the field values called out directly in text frames in the Variable Text Editor, which is what I assume you're trying to do, but it doesn't affect the values of the fields returned by the Field function in other rules. Quote Link to comment Share on other sites More sharing options...
Fellsway Posted November 6, 2012 Author Share Posted November 6, 2012 That worked Dan! Thanks guys! Quote Link to comment Share on other sites More sharing options...
Fellsway Posted November 7, 2012 Author Share Posted November 7, 2012 Dan, how about if I would want to search for the word "blank" and change it to color white? Quote Link to comment Share on other sites More sharing options...
step Posted November 7, 2012 Share Posted November 7, 2012 I'm not Dan, but I think this modification should work for you: for (var i in FusionPro.Fields) FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "blank", "[color="Red"]<color name=\"White\">blank</color> [/color]")); Quote Link to comment Share on other sites More sharing options...
Fellsway Posted November 7, 2012 Author Share Posted November 7, 2012 Step, that inserted the words "<color name=\"White\">blank</color>" in my text frame. Quote Link to comment Share on other sites More sharing options...
step Posted November 7, 2012 Share Posted November 7, 2012 You need to make sure that "treat return strings as tagged text" is checked in the text box Quote Link to comment Share on other sites More sharing options...
esmith Posted November 7, 2012 Share Posted November 7, 2012 Step and I think alike, but I think Dan's solution only works for variables placed directly into a text frame rather than used in rules. To do what you are asking now, I think you'd have to go back to my solution and replace noBlanks[s] = Field(s+startField).replace(/blank/g," "); with noBlanks[s] = Field(s+startField).replace(/blank/g,"[color=Red]<color name=\"White\">blank</color>[/color]"); and then create a text rule which pulls the correct element from the array. In the Rule dialog, you would be able to check for tagged text. Of course, Dan tends to know things about FP that we don't so he may have a better (aka simpler) solution. On a side note, this is why it is often helpful to explain what you are trying to accomplish in full rather than providing bits of information at a time. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 7, 2012 Share Posted November 7, 2012 Step, that inserted the words "<color name=\"White\">blank</color>" in my text frame. You need to make sure that "treat return strings as tagged text" is checked in the text box Well, this is something you would do in OnRecordStart, so there's no box to check. Here is where the Building Blocks dialog is your friend. If you open it up and go to the Objects tab, then expand "FusionPro (Global)", Composition, and Variables, then double-click on AddVariable, it inserts this signature: FusionPro.Composition.AddVariable(varName, varValue [,bTreatAsTagged])So what you need to do is set that optional third parameter to true, which has basically the same effect on that variable as the check box does for a regular rule, that is, it tells the composition engine to treat the value as tagged markup instead of as literal text. So change the logic to this: for (var i in FusionPro.Fields) FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), "blank", "<color name=\"White\">blank</color>"[color=SeaGreen], true[/color])); Eric is correct that this solution only works for variables placed directly into a text frame rather than used in rules, as I noted in my first post in the thread. However, you still need to denote that you want the value interpreted as tagged text. Quote Link to comment Share on other sites More sharing options...
Fellsway Posted November 7, 2012 Author Share Posted November 7, 2012 Thanks guys! Quote Link to comment Share on other sites More sharing options...
knaselk Posted November 26, 2012 Share Posted November 26, 2012 This was very helpful to me as well. I used Dan's OnRecordStart. Quick question (and please forgive my ignorance), how would you format multiple find/replace statements in the OnRecordStart Rule? For example, I'd like to replace "$", "0.", ".00", and "%" with "". Is this possible? Any help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
step Posted November 26, 2012 Share Posted November 26, 2012 I haven't tested this myself but you could give this a try: for (var i in FusionPro.Fields) FusionPro.Composition.AddVariable(i, ReplaceSubstring(Field(i), /\$0?|^0*|\.0{2}|%/g, "", true)); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 26, 2012 Share Posted November 26, 2012 For example, I'd like to replace "$", "0.", ".00", and "%" with "". So you want both "$0.10" and "$10.00" to turn into "10"? Quote Link to comment Share on other sites More sharing options...
knaselk Posted November 27, 2012 Share Posted November 27, 2012 (edited) Correct. I'm provided with data that reads $1.00 or $0.50 as an example. Depending on whether the amount is greater than .99, I'll insert a dollar sign prior or a cents sign after the number. The design calls for no decimals except for an instance where there is both dollars and cents ($1.50). I did see your post in another thread about multiple "find and replaces", but couldn't seem to get it to work on "OnRecordStart". This is still pretty new to me. Thanks for any help. - Oh thanks Step, I missed your post. I'll give that a try. Edited November 27, 2012 by knaselk Quote Link to comment Share on other sites More sharing options...
knaselk Posted November 27, 2012 Share Posted November 27, 2012 (edited) Thanks guys, I got it working. I used this from one of Dan's posts: var s = Field("Amount"); FusionPro.Composition.AddVariable s = ReplaceSubstring(s, "$", ""); s = ReplaceSubstring(s, "0.", ""); s = ReplaceSubstring(s, ".00", ""); s = ReplaceSubstring(s, "%", ""); return s; Then I used a second rule to insert the superscript symbols before or after, depending on the original amount field. I'm sure there's a more elegant way of doing it, but it works for me. And, I actually understand it Thanks again! Edited November 27, 2012 by knaselk Quote Link to comment Share on other sites More sharing options...
step Posted November 27, 2012 Share Posted November 27, 2012 I think that this code is going to be problematic for instances where there is a 0 before the first decimal but is not the first number. For example: "$10.00" will return 100. I commented off to the side of each line of code what the expected result will be and highlighted in red what is being replaced by each line of code. var s = Field("Amount"); FusionPro.Composition.AddVariable s = ReplaceSubstring(s, "$", ""); //$10.00 s = ReplaceSubstring(s, "0.", ""); //10.00 s = ReplaceSubstring(s, ".00", ""); //100 s = ReplaceSubstring(s, "%", ""); //100 return s; //100 This is why I felt it best to use a regular expression. Quote Link to comment Share on other sites More sharing options...
knaselk Posted November 27, 2012 Share Posted November 27, 2012 Oh, you're right! That did not occur to me. 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.