Go Back   PTI Marketing Technologies User Community > Software-Related Talk > The JavaScript Library > Graphic Rules

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 15th, 2015, 03:22 PM
iprint2 iprint2 is offline
Junior Community Member
 
Join Date: Apr 2014
Posts: 18
Default Placing Graphics based on two fields

Hey everyone,

So, im new here and fairly new to coding in general. But im trying to set up a rule so that i can eliminate quite a bit of up front end work on excel documents we get in monthly for a mailing.

The short version is, as an example, i have a pdf with 2 pages and there are three graphic frames, one on page one and two on page two. What i need to do is place a graphic based on a number from column p1 (1-14) in frame 1, then when that is done, move to frame 2 and pull a number from column p2 (1-14) then move to frame 3 etc...

the tricky part is that if p2 is empty, i need to pull from a different column, protocol. And that will be a if its this number use this graphic else use this graphic.
the same will apply, if p1, and p2 have values, and p3 is blank, i need it to switch too the protocol program.

So the other tricky thing i need is that if p2 pulls from protocol, i need p3 to be blank, so it doesn't place the protocol graphic twice.


This is the code i have now. Which i know is not right, but i wanted to have a base to build on. The red is basically just want i want to happen where i imagine it needs to happen.


//if there is an entry in P1 return corresponding resource- (this is working right now)
if (Field("P1") == 1)
{
return Resource("Heart disease1.pdf");
}
else if (Field("P1") == 2)
{
return Resource("Heart failure2.pdf");
}


// This second set of code is for the second graphic frame, not the first.
// so basically i need the rule to read the above code for "frame 1"
// then the code below to apply to "Frame 2".
//Once "frame one" is full, move to "frame two", then Move to "frame 3" //when frame 2 is full. etc..


if (field("P2") == 3)
{
return Resource("Breathing3.pdf");
}

//Frame 3

if (field("P3") == 4)
{
return Resource("Kidney4.pdf");

// Then, if P2 or P3 is blank. I need the rule to pull from the Protocol column and insert one of two files.


if(field("P2") == null))
&& (Field("PROTOCOL") = 704)
{
return Resource("Closing letter15.pdf");
}
else if (Field("PROTOCOL") = 712) {
return Resource("ClosingLetter16");
}

// Then i need the rule to determine that if P2 has the last insert(P3 is blank). Then it should stop, and not insert anything into "frame 3"



Any help would be great!
Thanks
Jason
__________________
iPrint
Fusion Pro VDP Creator 9.3.22
Acrobat 11.0.10 and DC

Mac OS 10.10
Reply With Quote
  #2  
Old May 15th, 2015, 04:47 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 921
Default Re: Placing Graphics based on two fields

Well I can't say for certain that I really know what you're trying to do. Collecting your template and data file to post to the site would make it easier to help you. At least knowing what version of FP you're using would be pretty insightful.

Anyway, what I would do is create a graphic rule and set it to "Re-evaluate this rule for every graphic frame." Then you want to name your various graphic frames by which field they should pull from: "p1", "p2", and "p3" respectively. Your graphic rule would look like this:
Code:
var frameName = FusionPro.Composition.CurrentFlow.name;

var [p1,p2,p3] = [Field("P1"),Field("P2"),Field("P3"),Field("PROTOCOL")].filter(String);

var pdfMap = {
    "1": "Heart disease1.pdf",
    "2": "Heart failure2.pdf",
    "3": "Breathing3.pdf",
    "4": "Kidney4.pdf",
    "704": "Closing letter15.pdf",
    "712": "Closing letter16.pdf"
}

var field = eval(frameName);
return (field) ? Resource(pdfMap[field]) : NullResource();
Then apply that rule to each frame. Basically what's happening is I've created an array of your 3 fields "P1", "P2", "P3", and the "PROTOCOL" field. Those values are assigned to variables: 'p1', 'p2', and 'p3'. I filtered out the empty variables so if all values exist for example:
Code:
var [p1,p2,p3] = ["1","3","4","704"].filter(String);
// p1 = 1
// p2 = 3
// p3 = 4
// and protocol is not used
If there's no value for Field("P2"), this would happen:
Code:
var [p1,p2,p3] = ["1","","4","704"].filter(String);
// p1 = 1
// p2 = 4
// p3 = 704
I used the frame name to determine which variable the rule should pull the graphic for (p1, p2, or p3) and then use the "pdfMap" to determine which PDF to pull for each variables value. If the variable is null a NullResource is returned as would be the case for p3 in:
Code:
var [p1,p2,p3] = ["1","","","704"].filter(String);
// p1 = 1
// p2 = 704
// p3 = *null*
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn

Last edited by step; May 18th, 2015 at 12:42 PM..
Reply With Quote
  #3  
Old May 18th, 2015, 10:29 AM
iprint2 iprint2 is offline
Junior Community Member
 
Join Date: Apr 2014
Posts: 18
Default Re: Placing Graphics based on two fields

Sorry about that. Im on Fusion Pro 9.3.6

Thanks for the response.
Ill give all that a shot and if i cant get it after that, Ill post a sample of what Im doing to make it a little clearer.

Jason
__________________
iPrint
Fusion Pro VDP Creator 9.3.22
Acrobat 11.0.10 and DC

Mac OS 10.10
Reply With Quote
  #4  
Old May 18th, 2015, 10:32 AM
iprint2 iprint2 is offline
Junior Community Member
 
Join Date: Apr 2014
Posts: 18
Default Re: Placing Graphics based on two fields

Another question. Would i apply this code to each graphic frame? Or is this more on an on record start kinda thing?

*Sorry i just read the apply to each frame part in your post.
__________________
iPrint
Fusion Pro VDP Creator 9.3.22
Acrobat 11.0.10 and DC

Mac OS 10.10

Last edited by iprint2; May 18th, 2015 at 10:34 AM..
Reply With Quote
Old May 18th, 2015, 11:44 AM
iprint2
This message has been deleted by iprint2.
  #5  
Old May 18th, 2015, 12:53 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 921
Default Re: Placing Graphics based on two fields

Unfortunately it doesn't look like your zip file contains the .cfg, .def, or .dif files that are generated when you collect your template in FP. Regardless, since I'm running an older version of FusionPro, it wouldn't be much help to me anyway.

If you've imported all of your PDFs as resources your return line needs to look like this:
Code:
return (field) ? Resource(pdfMap[field]) : NullResource();
If you want to add the resources on the fly:
Code:
return (field) ? CreateResource(pdfMap[field], 'graphic') : NullResource();
Quote:
Originally Posted by iprint2 View Post
Another question. Would i apply this code to each graphic frame? Or is this more on an on record start kinda thing?
This does not go in the OnRecordStart callback. Yes, apply the same graphic rule to each of your frames.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #6  
Old May 18th, 2015, 02:52 PM
iprint2 iprint2 is offline
Junior Community Member
 
Join Date: Apr 2014
Posts: 18
Default Re: Placing Graphics based on two fields

If you've imported all of your PDFs as resources your return line needs to look like this:
Code:
return (field) ? Resource(pdfMap[field]) : NullResource();
If you want to add the resources on the fly:
Code:
return (field) ? CreateResource(pdfMap[field], 'graphic') : NullResource();
Ok, So i uploaded a new batch of files in case anyone else wants to try.

Also I tried changing the return line to Resource, i also tried to just insert the resource using the building block tool only did it for resource 1). Im still just getting a return value of Resource("<None>") when i validate it. So im guessing its missing something that needs to stop it from getting to nullresource.

This is what i have now

Code:
var frame = FusionPro.Composition.CurrentFlow.name;


var [f1,f2,f3] = [Field("P1"),Field("P2"),Field("P3"),Field("PROTOCOL")].filter(String);

var pdfMap = {
    "1": Resource("Heart disease1.pdf"),
    "2": "Heart failure2.pdf",
    "3": "Breathing3.pdf",
    "4": "Kidney4.pdf",
    "704":"Closing letter15.pdf",
    "712": "ClosingLetter16"
}

var field = eval(frame);

return (field) ? Resource(pdfMap[frame]) : NullResource();
Attached Files
File Type: zip healthtel java code.zip (231.2 KB, 10 views)
__________________
iPrint
Fusion Pro VDP Creator 9.3.22
Acrobat 11.0.10 and DC

Mac OS 10.10
Reply With Quote
  #7  
Old May 18th, 2015, 04:41 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 921
Default Re: Placing Graphics based on two fields

Quote:
Originally Posted by step View Post
Anyway, what I would do is create a graphic rule and set it to "Re-evaluate this rule for every graphic frame."
It doesn't look like you followed that step (pardon my pun). Open up your "InsertPicture_New Rule" rule and tick the box beside "Re-evaluate this rule for every graphic frame" above the "expressions" text frame and beneath the "Comment" text frame.

And while you can do this:
Code:
"1": Resource("Heart disease1.pdf"),
It's easier to just apply the resource function at the return line. Not to mention, you'd have to do it for every resource in that object.

Your template works for me when I set the rule to re-evaluate for every graphic frame and have the code as:
Code:
var frameName = FusionPro.Composition.CurrentFlow.name;

var [p1,p2,p3] = [Field("P1"),Field("P2"),Field("P3"),Field("PROTOCOL")].filter(String);

var pdfMap = {
    "1": "Heart disease1.pdf",
    "2": "Heart failure2.pdf",
    "3": "Breathing3.pdf",
    "4": "Kidney4.pdf",
    "704": "Closing letter15.pdf",
    "712": "Closing letter16.pdf"
}

var field = eval(frameName);
return (field) ? Resource(pdfMap[field]) : NullResource();
By the way, in validation, the rule is always going to return a null resource. That's because it needs the name of the frame (which isn't available at the validation stage) in order to return the resource. If you want to test the value of 'p1' when you're validating your rule, modify the code to look like this:
Code:
var frameName = (FusionPro.inValidation) ? "p1" : FusionPro.Composition.CurrentFlow.name;

var [p1,p2,p3] = [Field("P1"),Field("P2"),Field("P3"),Field("PROTOCOL")].filter(String);

var pdfMap = {
    "1": "Heart disease1.pdf",
    "2": "Heart failure2.pdf",
    "3": "Breathing3.pdf",
    "4": "Kidney4.pdf",
    "704": "Closing letter15.pdf",
    "712": "Closing letter16.pdf"
}

var field = eval(frameName);
return (field) ? Resource(pdfMap[field]) : NullResource();
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #8  
Old May 28th, 2015, 10:32 AM
iprint2 iprint2 is offline
Junior Community Member
 
Join Date: Apr 2014
Posts: 18
Default Re: Placing Graphics based on two fields

Step,
Thank you so much for your help with this. So far it is working perfectly!
Is there somewhere i can give you props for being super awesome and helpful?
__________________
iPrint
Fusion Pro VDP Creator 9.3.22
Acrobat 11.0.10 and DC

Mac OS 10.10
Reply With Quote
  #9  
Old May 28th, 2015, 11:58 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 921
Default Re: Placing Graphics based on two fields

Good I'm glad that's working for you! No props necessary though I appreciate it.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
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 02:37 PM.


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