Jump to content

Suppressing text frame based on field value


Recommended Posts

We are trying to hide a text frame when there is a image displayed in a graphic frame. Then suppress a different text frame when the image is not displayed in the graphic frame. The first few lines of care are present as reference to the entire OnRecordStart rule. I don't know if it is causing a conflict with the JavaScript at the end to suppress the text frames. When the graphic is there one frame suppress but when the graphic is not there neither text frame suppresses.

 

 

 

if (Field("LetterCode") == "A1")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A2")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A3")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A6")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A7")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A8")

{FusionPro.Composition.SetBodyPageUsage("A1", true);}

if (Field("LetterCode") == "A4")

{FusionPro.Composition.SetBodyPageUsage("A4", true);}

if (Field("LetterCode") == "A5")

{FusionPro.Composition.SetBodyPageUsage("A4", true);}

if (Field("LetterCode") == "B1")

{FusionPro.Composition.SetBodyPageUsage("B1", true);}

if (Field("LetterCode") == "C1")

{FusionPro.Composition.SetBodyPageUsage("C1", true);}

if (Field("LetterCode") == "D1")

{FusionPro.Composition.SetBodyPageUsage("D1", true);}

if (Field("LetterCode") == "E1")

{FusionPro.Composition.SetBodyPageUsage("E1", true);}

if (Field("LetterCode") == "A11")

{FusionPro.Composition.SetBodyPageUsage("A11", true);}

if (Field("LetterCode") == "A12")

{FusionPro.Composition.SetBodyPageUsage("A11", true);}

if (Field("LetterCode") == "A13")

{FusionPro.Composition.SetBodyPageUsage("A11", true);}

if (Field("LetterCode") == "B2")

{FusionPro.Composition.SetBodyPageUsage("B2", true);}

 

var MyPic = CreateResource(Field("Photo"), "graphic", true);

if (MyPic.exists)

{

var PicFrame = FindTextFrame("PicL");

return PicFrame.suppress = true;

return NullResource();

}

else

{

var MyFrame = FindTextFrame("NoPicL");

return MyFrame.suppress = true;

return NullResource();

}

Link to comment
Share on other sites

Callback rules can not "return" values; you use them to do things in the background (like set frames to suppress). Assuming each of your template pages contains common elements, you will need to name "common" frames on each page uniquely for the suppression to work correctly below.

 

We are trying to hide a text frame when there is a image displayed in a graphic frame. Then suppress a different text frame when the image is not displayed in the graphic frame. The first few lines of care are present as reference to the entire OnRecordStart rule. I don't know if it is causing a conflict with the JavaScript at the end to suppress the text frames. When the graphic is there one frame suppress but when the graphic is not there neither text frame suppresses.

 

Let's assign names to the various frames you're using:

GraphicA -- return image if present

PicL -- hide this frame when graphic IS present

NoPicL -- hide this frame when graphic NOT present

 

So on your template pages, you would have each frame named by the above names PLUS a unique identifier. For example, the three frames on template page A1 might be named "GraphicA-A1", "PicL-A1" and "NoPicL-A1".

 

Next, let's simplify the BodyPageUsage code to make it a little easier to read. I also think it may wind up being necessary to set values for your various frame names into these conditions. I am replacing your:

if (Field("LetterCode") == "A1")
{FusionPro.Composition.SetBodyPageUsage("A1", true);}
.
.
if (Field("LetterCode") == "B2")
{FusionPro.Composition.SetBodyPageUsage("B2", true);}

 

with this:

switch (Field("LetterCode")) {
  case "A2":
  case "A3":
  case "A6":
  case "A7":
  case "A8":
  FusionPro.Composition.SetBodyPageUsage("A1", true);
  break;

  case "A5":
  FusionPro.Composition.SetBodyPageUsage("A4", true);
  break;

  case "A12":
  case "A13":
  FusionPro.Composition.SetBodyPageUsage("A11", true);
  break;

  default:
  FusionPro.Composition.SetBodyPageUsage(Field("LetterCode"), true); 
}

 

If I'm reading the "MyPic" code correctly, you are creating a resource based on a value in the field "Photo" which I presume either includes the full path to the image or the images are located in the same place as the FP template. I also assume the value in the data includes the proper extension (i.e. "\\pictures\\myimage.jpg").

 

Since you can not return a value in a callback rule, I believe "return NullResource();" is unnecessary in both positions (you would create a separate graphic rule to place an existing image in the graphic frame on each template page). The suppression action also does not require a "return". So your code might look something like:

 

var MyPic = CreateResource(Field("Photo"), "graphic", true);
if (MyPic.exists) {
  var PicFrame = FindTextFrame("PicL");
  PicFrame.suppress = true;
}
else {
  var MyFrame = FindTextFrame("NoPicL");
  return MyFrame.suppress = true;
}

 

But that alone is not going to work because (as mentioned above) we can't have multiple frames with the same EXACT name on each page. So instead, we'll initiate the variables for the various frames in the original SWITCH logic to look like this (and edit the frame names on the template pages accordingly):

 

switch (Field("LetterCode")) {
  case "A2":
  case "A3":
  case "A6":
  case "A7":
  case "A8":
  FusionPro.Composition.SetBodyPageUsage("A1", true);
  var picTrue = FindTextFrame("PicL-A1");
  var picFalse = FindTextFrame("NoPicL-A1");
  break;

  case "A5":
  FusionPro.Composition.SetBodyPageUsage("A4", true);
  var picTrue = FindTextFrame("PicL-A4");
  var picFalse = FindTextFrame("NoPicL-A4");
  break;

  case "A12":
  case "A13":
  FusionPro.Composition.SetBodyPageUsage("A11", true);
  var picTrue = FindTextFrame("PicL-A11");
  var picFalse = FindTextFrame("NoPicL-A11");
  break;

  default:
  FusionPro.Composition.SetBodyPageUsage(Field("LetterCode"), true);
  var picTrue = FindTextFrame("PicL-" + Field("LetterCode"));
  var picFalse = FindTextFrame("NoPicL-" + Field("LetterCode"));
}

 

Then to that we can add our suppression condition logic:

 

var MyPic = CreateResource(Field("Photo"), "graphic", true);
if (MyPic.exists) picTrue.suppress = true;
else picFalse.suppress = true;

 

Of course, I don't have a good way to test this logic so there may still be some errors, but I think we have made progress and can fix any leftover bugs after trying the above alterations. :)

Edited by esmith
Link to comment
Share on other sites

Below is the current code.

switch (Field("LetterCode")) {
  case "A1":
  case "A2":
  case "A3":
  case "A6":
  case "A7":
  case "A8":
  FusionPro.Composition.SetBodyPageUsage("A1", true);
  var picTrue = FindTextFrame("Sig-A1");
  var picFalse = FindTextFrame("NoSig-A1");
  break;

case "A4":
  case "A5":
  FusionPro.Composition.SetBodyPageUsage("A4", true);
  var picTrue = FindTextFrame("Sig-A4");
  var picFalse = FindTextFrame("NoSig-A4");
  break;

  case "A11":
  case "A12":
  case "A13":
  FusionPro.Composition.SetBodyPageUsage("A11", true);
  var picTrue = FindTextFrame("Sig-A11");
  var picFalse = FindTextFrame("NoSig-A11");
  break;

  case "B1":
  FusionPro.Composition.SetBodyPageUsage("B1", true);
  var picTrue = FindTextFrame("Sig-B1");
  var picFalse = FindTextFrame("NoSig-B1");
  break;

case "C1":
  FusionPro.Composition.SetBodyPageUsage("C1", true);
  var picTrue = FindTextFrame("Sig-C1");
  var picFalse = FindTextFrame("NoSig-C1");
  break;

case "D1":
  FusionPro.Composition.SetBodyPageUsage("D1", true);
  var picTrue = FindTextFrame("Sig-D1");
  var picFalse = FindTextFrame("NoSig-D1");
  break;

case "E1":
  FusionPro.Composition.SetBodyPageUsage("E1", true);
  var picTrue = FindTextFrame("Sig-E1");
  var picFalse = FindTextFrame("NoSig-E1");
  break;

  default:
  FusionPro.Composition.SetBodyPageUsage(Field("LetterCode"), true);
  var picTrue = FindTextFrame("Sig-" + Field("LetterCode"));
  var picFalse = FindTextFrame("NoSig-" + Field("LetterCode"));
}

if (StringToNumber(Field("Photo")) < StringToNumber("1"))
picTrue.suppress = true;
else picFalse.suppress = true;

 

I've changed the script at the bottom to identify if a number is present or not since the filename given in the data is "11111_1111.pdf" and not a full path. Trying to create a resource doesn't allow the suppression to work. All of the A1-A8 work but the remaining letters that DO NOT have a photo still use the frame that is for when a photo is there.

 

Thoughts?

Link to comment
Share on other sites

I've changed the script at the bottom to identify if a number is present or not since the filename given in the data is "11111_1111.pdf" and not a full path. Trying to create a resource doesn't allow the suppression to work. All of the A1-A8 work but the remaining letters that DO NOT have a photo still use the frame that is for when a photo is there.

 

Did you change the names of the text/graphic frames on each template page to be unique and match the naming in the code?

 

I'm not sure your condition makes sense. Converting a string to a number does not return a reliable number for testing. I'm also not sure what your data looks like for the various scenarios. If a pic does not exist for a record, does the field have nothing in it? If so, your condition could be:

if (Field("Photo") != "") picTrue.suppress = true;
else picFalse.suppress = true;

 

On a side note, you didn't need to add cases for the other Letter Codes. The default case already captured those scenarios by returning the template page name matching the Letter Code value. ;)

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...