Jump to content

Marcom Template not Implementing Rule


mmorse

Recommended Posts

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!

Link to comment
Share on other sites

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:

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:

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:


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:

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...