Printing Partners Posted February 20, 2018 Share Posted February 20, 2018 This should be fairly easy, I would think, but I can't seem to figure it out. I have a template where a User can upload 2 images into a template. If they only upload 1 image, I want to use that in both picture boxes in the template. Below is an over simplified script that fails, but it is essentially what I need: if (Field("SecondaryLogo") != "") return Field("SecondaryLogo"); else return Field("PrimaryLogo");My problem is how do I approach this as a rule in my template so Marcom knows what to do with it. Because it is a graphic rule, it wants me to return a graphic value. But how do you access User images uploaded in templates in a rule? Link to comment Share on other sites More sharing options...
step Posted February 20, 2018 Share Posted February 20, 2018 Would this work? var logo = Field("SecondaryLogo") ? Field("SecondaryLogo") : Field("PrimaryLogo"); return CreateResource(logo, 'graphic', true); Link to comment Share on other sites More sharing options...
Printing Partners Posted February 21, 2018 Author Share Posted February 21, 2018 Ste, That worked perfectly! It was the "CreateResource" that I was not aware of. Saw it, but didn't understand how it worked. Also, thanks for introducing me to the short hand conditional statement. I had not used that before. Learned two things today! Now to go study up on both of them more. Thanks for the help! ________________________ The complete rule that I used, in case anyone else is in the same boat I was. var logo = Field("SecondaryLogo") ? Field("SecondaryLogo") : Field("PrimaryLogo"); return CreateResource(logo, 'graphic', true); if (Field("SecondaryLogo") != "") return logo; else return Field("SecondaryLogo"); Link to comment Share on other sites More sharing options...
Dan Korn Posted February 21, 2018 Share Posted February 21, 2018 The complete rule that I used, in case anyone else is in the same boat I was. var logo = Field("SecondaryLogo") ? Field("SecondaryLogo") : Field("PrimaryLogo"); return CreateResource(logo, 'graphic', true); if (Field("SecondaryLogo") != "") return logo; else return Field("SecondaryLogo"); Most of that code is completely moot. Nothing after that second line that starts with "return" is ever going to be executed. The first two lines can be reduced to this: var logo = Field("SecondaryLogo") || Field("PrimaryLogo"); return CreateResource(logo, 'graphic', true); Or just: return CreateResource(Field("SecondaryLogo") || Field("PrimaryLogo"), 'graphic', true); Though you don't even need all of that. Since you're already in a graphic rule, the type will default to 'graphic'. And you probably don't want the last parameter to suppress an error message if neither graphic is found. So really all you need is this: return CreateResource(Field("SecondaryLogo") || Field("PrimaryLogo")); Link to comment Share on other sites More sharing options...
Recommended Posts