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 June 1st, 2015, 09:45 AM
mmorse mmorse is offline
Junior Community Member
 
Join Date: May 2015
Posts: 18
Default Marcom Template not Implementing Rule

Hello All -

I've run into a problem, where my Javascript rule works perfectly within Fusion Pro, but not within Marcom.

The rule:

var redSubOne = "<color name = \"PANTONE Red 032 C\">" + Field("dynamicSubOne") + "</color>";
var blueSubOne = "<color name = \"PANTONE 2945 C\">" + Field("dynamicSubOne") + "</color>";
var graySubOne = "<color name = \"PANTONE 430 C\">" + Field("dynamicSubOne") + "</color>";
var purpleSubOne = "<color name = \"PANTONE 266 C\">" + Field("dynamicSubOne") + "</color>";


if(Field("headerImage") == ("red.pdf")){
return redSubOne.toUpperCase();
}else if(Field("headerImage")== ("blue.pdf")){
return blueSubOne.toUpperCase();
}else if(Field("headerImage")==("gray.pdf")){
return graySubOne.toUpperCase();
}else{
return purpleSubOne.toUpperCase();
}


The Problem: Within Marcom, the rule defaults to the final "else" statement, always returning the purple font. Again, this rules work fine within Fusion Pro.

Any thoughts or input would be very much appreciated.

Thanks!
Reply With Quote
  #2  
Old June 1st, 2015, 10:41 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Marcom Template not Implementing Rule

Personally, I've never used MarcomCentral (there's a completely separate forum for MC specific questions that you may have better luck with) but if it's always defaulting to the purple color, I would think that MC is reading the value of the "headerImage" field differently than FP is locally. My suspicion is that in MC perhaps the field value is prepended with a path to the pdf? If that's the case, one way to get around that would be to use the "GetFileName" function to basically remove the path from the field value when checking if it's equal to "red.pdf" or whatever value:
Code:
if(GetFileName(Field("headerImage")) == ("red.pdf")){
return redSubOne.toUpperCase(); 
}
.
.
.
As a side note, you really shouldn't need to make that entire line ('redSubOne') all uppercase since it contains your tags. Instead you could just force the field itself to uppercase when you're defining the variable and leave the tags untouched:
Code:
var redSubOne = "<color name = \"PANTONE Red 032 C\">" + ToUpper(Field("dynamicSubOne")) + "</color>";
You may also want to take advantage of a switch statement here in lieu of all of the "else if" statements which would allow you to clean the code up a bit:
Code:
var color = '';
switch (GetFileName(Field("headerImage"))){
    case "red.pdf":
        color = "PANTONE Red 032 C";
    break;
    case "blue.pdf":
        color = "PANTONE 2945 C";
    break;
    case "gray.pdf":
        color = "PANTONE 430 C";
    break;
    default:
        color = "PANTONE 266 C";
}
return '<color name="' + color + '">' + ToUpper(Field("dynamicSubOne")) + '</color>';
If the issue value of the field is differing on MC by more than just a prepended path (casing for example), I suppose you could do a more generic search of that field value and search for any presence of "red.pdf" in "headerImage" regardless of casing by using a regular expression and modifying the code to look like this:
Code:
var header = String(Field("headerImage").match(/(red|blue|gray)\.pdf/ig));
var color = '';

switch (ToLower(header)){
    case "red.pdf":
        color = "PANTONE Red 032 C";
    break;
    case "blue.pdf":
        color = "PANTONE 2945 C";
    break;
    case "gray.pdf":
        color = "PANTONE 430 C";
    break;
    default:
        color = "PANTONE 266 C";
}

return '<color name="' + color + '">' + ToUpper(Field("dynamicSubOne")) + '</color>';
That would match "red.pdf", "RED.pdf", "/path/to/red.PDF", etc.
__________________
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 June 2nd, 2015, 10:58 AM
mmorse mmorse is offline
Junior Community Member
 
Join Date: May 2015
Posts: 18
Default Re: Marcom Template not Implementing Rule

Thanks Ste!
That worked perfectly, and a much more elegant solution.

Much Appreciated!
Matt
Reply With Quote
Reply

Tags
font not working, javascript

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:08 PM.


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