Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 8th, 2017, 01:20 PM
TotalChoiceNate TotalChoiceNate is offline
Junior Community Member
 
Join Date: Dec 2016
Posts: 17
Default Mass Entity Rule Possible?

Hello all!

I am working with a bit of a pain customer. When I enter certain extended characters in the MCC Storefront it either switches them with greek symbols or switches them back to a standard char set (The character in question is this special apostrophe that their style guide requires).

The support workaround for this is to type in the entity with a replace substring rule, but the way that they set it up is on an individual field basis, which on some templates can get quite long!

So, my question is a two-fold question:
  • Is there a way to clean up the code below in to a single rule rather than having a separate line for each character?
  • Is there a way to do this as a global replace substring rule versus having to list each field on its own line?

Code in question:
Code:
//The end-user needs to enter in entity values to access special characters. However the following is necessary as MCC tries to "help"
//in converting entities. The following replace substring will fix the "help" provided so that you can actually return the entity typed in.
FusionPro.Composition.AddVariable("Date and Time Information",ReplaceSubstring(Field("Date and Time Information"),"&","&"),true);
FusionPro.Composition.AddVariable("Event Information",ReplaceSubstring(Field("Event Information"),"&","&"),true);
FusionPro.Composition.AddVariable("Direction 1 Information",ReplaceSubstring(Field("Direction 1 Information"),"&","&"),true);
FusionPro.Composition.AddVariable("Direction 2 Information",ReplaceSubstring(Field("Direction 2 Information"),"&","&"),true);
FusionPro.Composition.AddVariable("Direction 3 Information",ReplaceSubstring(Field("Direction 3 Information"),"&","&"),true);
FusionPro.Composition.AddVariable("Direction 4 Information",ReplaceSubstring(Field("Direction 4 Information"),"&","&"),true);

FusionPro.Composition.AddVariable("Date and Time Information",ReplaceSubstring(Field("Date and Time Information"),"&rsquor","’"),true);
FusionPro.Composition.AddVariable("Event Information",ReplaceSubstring(Field("Event Information"),"&rsquor","’"),true);
FusionPro.Composition.AddVariable("Direction 1 Information",ReplaceSubstring(Field("Direction 1 Information"),"&rsquor","’"),true);
FusionPro.Composition.AddVariable("Direction 2 Information",ReplaceSubstring(Field("Direction 2 Information"),"&rsquor","’"),true);
FusionPro.Composition.AddVariable("Direction 3 Information",ReplaceSubstring(Field("Direction 3 Information"),"&rsquor","’"),true);
FusionPro.Composition.AddVariable("Direction 4 Information",ReplaceSubstring(Field("Direction 4 Information"),"&rsquor","’"),true);

FusionPro.Composition.AddVariable("Date and Time Information",ReplaceSubstring(Field("Date and Time Information"),"'","’"),true);
FusionPro.Composition.AddVariable("Event Information",ReplaceSubstring(Field("Event Information"),"'","’"),true);
FusionPro.Composition.AddVariable("Direction 1 Information",ReplaceSubstring(Field("Direction 1 Information"),"'","’"),true);
FusionPro.Composition.AddVariable("Direction 2 Information",ReplaceSubstring(Field("Direction 2 Information"),"'","’"),true);
FusionPro.Composition.AddVariable("Direction 3 Information",ReplaceSubstring(Field("Direction 3 Information"),"'","’"),true);
FusionPro.Composition.AddVariable("Direction 4 Information",ReplaceSubstring(Field("Direction 4 Information"),"'","’"),true);
Reply With Quote
  #2  
Old September 8th, 2017, 02:35 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Mass Entity Rule Possible?

I think this might work:
Code:
// An object of values to find as the keys,
// and the string to replace them with as the value.
var charMap = {
// Find      : Replace
   "&"   : "&",
   "&rsquor" : "’",
   "'"       : "’",
}

// Loop through all of the fields.
for (var field in FusionPro.Fields) {
  // Loop through all of the find/replace values for current field.
  for (var find in charMap) {
    var replace = charMap[find];
    FusionPro.Composition.AddVariable(field,
      ReplaceSubstring(Field(field), find, replace), true);
  }
}
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old September 8th, 2017, 02:39 PM
TotalChoiceNate TotalChoiceNate is offline
Junior Community Member
 
Join Date: Dec 2016
Posts: 17
Default Re: Mass Entity Rule Possible?

Thanks for the reply, in your code which of the values do I need to replace with names from my template, if any?
Reply With Quote
  #4  
Old September 8th, 2017, 05:11 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,305
Default Re: Mass Entity Rule Possible?

Quote:
Originally Posted by TotalChoiceNate View Post
Thanks for the reply, in your code which of the values do I need to replace with names from my template, if any?
None. That's the beauty of the "for (var field in FusionPro.Fields)" code; it just iterates through all of the fields in the data, whatever their names are.

Although, I think there's a way to fix at least part of the problem (entities such as "&" in the output) without doing that. I suspect that these "extended" characters are showing up correctly when the data fields are used directly in text frames in your job, and that the problem is related to when you're calling the Field function in rules. So if you replace the Field calls in your other rules with TaggedDataField, and possibly check the "Treat returned strings as tagged text" box in those rules as well, I think that will prevent the entities from appearing in your output.

As for why MarcomCentral inserts "straight" quotes instead of "curly" quotes, that's a question for the MarcomCentral forum.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; September 8th, 2017 at 05:30 PM..
Reply With Quote
  #5  
Old September 12th, 2017, 12:20 PM
TotalChoiceNate TotalChoiceNate is offline
Junior Community Member
 
Join Date: Dec 2016
Posts: 17
Default Re: Mass Entity Rule Possible?

That's correct, this rule appears to be the perfect solution, but I'm not sure it is seaching the fields to replace characters as nothing is changing. Normally these quotes are used to specify an Alumni year and by using the class year as its own field it inserts the apostrophe fine (see below)

Code:
if (Field("Class Year") == "")
	return "";
else
	return ' ’'+Field("Class Year");
But once they type the custom text (same characters) in to a storefront field it breaks. I replaced the rule within the template to what I have below and it doesn't seem to be working.

Code:
// An object of values to find as the keys,
// and the string to replace them with as the value.
var charMap = {
// Find      : Replace
   "’":"’",
   "’":"'",
   "¼":"¼",
   "½":"½",
   "¾":"¾",
   "—":"–",
   "—":"—",
}

// Loop through all of the fields.
for (var field in FusionPro.Fields) {
  // Loop through all of the find/replace values for current field.
  for (var find in charMap) {
    var replace = charMap[find];
    FusionPro.Composition.AddVariable(field,
      ReplaceSubstring(Field(field), find, replace), true);
  }
}
Just so I understand correctly, I should replace the red text with "TaggedDataField"? Currently this is the only rule that I have in the template and is an OnRecordStart callback which doesn't give me the option to treated returned strings as tagged text.
Reply With Quote
  #6  
Old September 12th, 2017, 12:27 PM
TotalChoiceNate TotalChoiceNate is offline
Junior Community Member
 
Join Date: Dec 2016
Posts: 17
Default Re: Mass Entity Rule Possible?

Are you able to move the thread to the MarcomCentral forum or should I create new?
Reply With Quote
  #7  
Old September 12th, 2017, 02:39 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,305
Default Re: Mass Entity Rule Possible?

Quote:
Originally Posted by TotalChoiceNate View Post
That's correct, this rule appears to be the perfect solution, but I'm not sure it is seaching the fields to replace characters as nothing is changing.
What specifically is not changing? How is the data being brought into the template? Does it simply call out the data field in the text? Or is there another rule involved?
Quote:
Originally Posted by TotalChoiceNate View Post
But once they type the custom text (same characters) in to a storefront field it breaks. I replaced the rule within the template to what I have below and it doesn't seem to be working.
It's getting hard to analyze specifically what's going on in your template just from what's been posted in this thread. At the very least, seeing what your output looks like could be helpful. The collected template would probably be more illuminating. Though a full analysis of the issue may only be possible by going through Support so that I (or someone else here at MarcomCentral) could fully examine the files being used for the composition. It could be a font issue, or something else that needs to be fixed in a different way.
Quote:
Originally Posted by TotalChoiceNate View Post
Just so I understand correctly, I should replace the red text with "TaggedDataField"?
No. When I said, "replace the Field calls in your other rules with TaggedDataField," I meant, any other rules besides OnRecordStart.
Quote:
Originally Posted by TotalChoiceNate View Post
Currently this is the only rule that I have in the template
Okay. So you mean those data field values are being brought in directly in text frames? In that case, you shouldn't really need to do anything. FusionPro should properly process those entities in the tagged markup data that MarcomCentral is generating.
Quote:
Originally Posted by TotalChoiceNate View Post
and is an OnRecordStart callback which doesn't give me the option to treated returned strings as tagged text.
Right. The OnRecordStart rule doesn't actually return anything that affects the composition, so the option of whether to treat the return value as tagged is moot.

The way you're telling FusionPro whether to treat the value as tagged is in that last parameter in the call to FusionPro.Composition.AddVariable. Setting it to true is equivalent to having a rule with the same name as the first parameter (the variable name) and checking that "Treat as tagged" box. Setting it to false is the same as leaving that box unchecked.
Quote:
Originally Posted by TotalChoiceNate View Post
Are you able to move the thread to the MarcomCentral forum or should I create new?
You could create a new thread there just about the question about how MarcomCentral inserts the quotes into the data file it generates. This thread can be continued though.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #8  
Old September 14th, 2017, 03:06 PM
lance's Avatar
lance lance is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Cedar Falls, Iowa
Posts: 30
Default Re: Mass Entity Rule Possible?

Quote:
Originally Posted by TotalChoiceNate View Post
That's correct, this rule appears to be the perfect solution, but I'm not sure it is seaching the fields to replace characters as nothing is changing. Normally these quotes are used to specify an Alumni year and by using the class year as its own field it inserts the apostrophe fine (see below)

Code:
if (Field("Class Year") == "")
	return "";
else
	return ' ’'+Field("Class Year");
But once they type the custom text (same characters) in to a storefront field it breaks. I replaced the rule within the template to what I have below and it doesn't seem to be working.

Code:
// An object of values to find as the keys,
// and the string to replace them with as the value.
var charMap = {
// Find      : Replace
   "’":"’",
   "’":"'",
   "¼":"¼",
   "½":"½",
   "¾":"¾",
   "—":"–",
   "—":"—",
}

// Loop through all of the fields.
for (var field in FusionPro.Fields) {
  // Loop through all of the find/replace values for current field.
  for (var find in charMap) {
    var replace = charMap[find];
    FusionPro.Composition.AddVariable(field,
      ReplaceSubstring(Field(field), find, replace), true);
  }
}
Just so I understand correctly, I should replace the red text with "TaggedDataField"? Currently this is the only rule that I have in the template and is an OnRecordStart callback which doesn't give me the option to treated returned strings as tagged text.
I was playing around with this, and I was getting the same issue, where nothing appeared to change. I think the problem is that as it loops through each entry in the charMap it is re-adding a variable, overwriting everything it had done up to that point (i.e. the changes aren't cumulative from entry to entry). So really all it is doing is a ReplaceSubstring() on the very last entry in the charMap. If that entry doesn't result in a change, then it appears as nothing has changed. I think.
__________________
Lance Wente
Woolverton Printing
Cedar Falls, IA 50613
800.670.7713
FusionPro Desktop 10.0.16 - Acrobat 11.0.23 - OS X 10.11.6 Mac Pro
Reply With Quote
  #9  
Old September 14th, 2017, 05:13 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Mass Entity Rule Possible?

Quote:
Originally Posted by lance View Post
I think the problem is that as it loops through each entry in the charMap it is re-adding a variable, overwriting everything it had done up to that point (i.e. the changes aren't cumulative from entry to entry). So really all it is doing is a ReplaceSubstring() on the very last entry in the charMap. If that entry doesn't result in a change, then it appears as nothing has changed. I think.
The ReplaceSubstring function is replacing each occurrence of the 'find' variable in each FusionPro field with the corresponding 'replace' variable defined in the 'charMap' object and then redefining the value of the field with the result. Here's a static example to show you how the code does replace more than just the last character in the 'charMap':
Code:
var charMap = {
   "R": "F",
   "ond": "and",
   "L" : "S",
   "ov": "m",
   "s": "lls",
   "d": "",
   "ay": "eld",
}

var field = 'Everyone Loves Raymond';

for (var find in charMap) {
  var replace = charMap[find];
  field = ReplaceSubstring(field, find, replace);
}

return field; // Everyone Smells Feldman
As Dan mentioned in an earlier post, it is hard to say why it's not working for you without being able to see your template.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #10  
Old September 14th, 2017, 06:02 PM
lance's Avatar
lance lance is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Cedar Falls, Iowa
Posts: 30
Default Re: Mass Entity Rule Possible?

Code:
// An object of values to find as the keys,
// and the string to replace them with as the value.
var charMap = {
// Find      : Replace
   "&"   : "&",
   "&rsquor" : "’",
   "'"       : "’",
}

// Loop through all of the fields.
for (var field in FusionPro.Fields) {
  // Loop through all of the find/replace values for current field.
  for (var find in charMap) {
    var replace = charMap[find];
    FusionPro.Composition.AddVariable(field,
      ReplaceSubstring(Field(field), find, replace), true);
  }
}
The red highlighted part is what I am questioning.

Isn't this just re-adding (overwriting) and re-defining the variable each iteration through the for loop?
__________________
Lance Wente
Woolverton Printing
Cedar Falls, IA 50613
800.670.7713
FusionPro Desktop 10.0.16 - Acrobat 11.0.23 - OS X 10.11.6 Mac Pro
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:41 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.