Jump to content

Dan Korn

Members
  • Posts

    4,884
  • Joined

  • Days Won

    17

Posts posted by Dan Korn

  1.  

    52 minutes ago, psmosser said:

    Solved it. This seems to work if anyone else needs it. 

     

    FindGraphicFrame("QR Code Front-001").x =Field("Xposition"), FindGraphicFrame("QR Code Front-001").y =Field("yposition"), FindGraphicFrame("QR Code Front-001").width =Field("Xsize"), FindGraphicFrame("QR Code Front-001").height =Field("Ysize");

     

     

    Sure, but you don't have to keep calling FindGraphicFrame over and over.  You can put the result of that into a variable, like so:
     

    var frame = FindGraphicFrame("QR Code Front-001");
    frame.x = Field("Xposition");
    frame.y = Field("yposition");
    frame.width = Field("Xsize");
    frame.height = Field("Ysize");

     

  2. Well, I can't test it out without the rest of the job, including the primary data file and the XDF, but that looks right.

    Though you can also accomplish this without any JavaScript at all by setting up the XDF as a Secondary Data Source (from the menu, FusionPro -> Data Definition -> Secondary Data Sources, click Add to define the Excel file as a data source), then check the "Filter/map records where" box, set up the mapping between the XDF field "Manager" and the primary field "Text_Manager", and check the "Add to field list with prefix" box.  Then the matched fields from the XDF will appear in the Text Editor variables list, and you can use them directly.

  3. Thomas's solution is good, but there's a handy FormatPhoneNumber function built into FusionPro which will do most of the heavy lifting for you.  So you should be able to just do something like this:

    var nums = {
      "Direct": Field("Direct Number"),
      "Mobile": Field("Mobile Number"),
      "Fax": Field("Fax Number"),
    };
    
    var result = [];
    for (var label in nums)
    {
        if (nums[label])
            result.push(label.bold() + " " + FormatPhoneNumber(nums[label]));
    }
    return result.join(" ");
     
  4. 35 minutes ago, Cat said:

    I'm so frustrated not understanding this tool instantly! (primal scream... yeah I know it's an unrealistic expectation :) Thank you for the example!

    You're doing fine.  It's a complicated program with a lot of features.  I don't know if there's anyone who understands everything about it.  I'm still learning new tricks, and I've been working on FusionPro since its inception, 25 years ago.

    35 minutes ago, Cat said:

    I will work on testing this to help learn more. I have used Python to do a lot of functionality in another web-to-print solution and I tend to try a code based solution first because of it.

    I don't mean to discourage you from writing code.  Far from it: I'm a big fan of coding.  (It's what I do!)  I just wanted to clarify that this, like many tasks, can be accomplished without any coding, which many people prefer.

    Interesting that you mention Python.  We actually had a bit of a debate years ago when we added the rules scripting system about what language to use.  The finalists were JavaScript and Python.  I think we ultimately made the right choice with JavaScript.  (It's a bit more forgiving in some ways that Python, given Python's mandatory whitespace for one thing, though I know there are differences of opinion.) But Python has its charms as well.

  5. 7 hours ago, Cat said:

    The drag & drop rule wants to have a text value in both the text and graphic versions, so the drag & drop will not work.

    I don't think that's true.  If you create a Graphic Drag-and-Drop rule, it will tell you to put either a Graphic Resource or a Graphic Rule into the "Return" box.

    I was able to create two other graphic rules: One based on the "Insert Picture Rule" Form, for the "if the image is uploaded" case, and another based on the Graphic "QR Barcode" Form, for the "generated by code" case, then use both of them in a Graphic Drag-and-Drop rule.

    But if you have it working in JavaScript, that's great.

    D&D.png

  6. You could just have a single graphic frame, and have it call out a graphic rule that returns either the generated or uploaded QR code.  That graphic rule could call another graphic rule as necessary.  Something like:

    if (Field("Upload") != "")
        return CreateResource(Field("Upload"));
    //else
    return Rule("QR Barcode: Barcode Data");


    This could be probably accomplished with a Drag-and-Drop Wizard rule as well, without any code.

    Posting the template would allow me to make a more specific recommendation.

  7. 2 hours ago, AngelBenitez said:

    Hello @Dan Korn; thank you for your response. I'm unsure if you are familiar with using MarcomCentral, but which one of these rules would I use to pull in the image based on an image collection? If so, do I need to take any additional steps to achieve this outcome?

    A graphic in an image collection in MarcomPortal is referenced by the graphic's file name.  So you would need this variation:

     

    if (Trim(ToLower(Field("YourFieldName"))) != "yes")
        return "";
    // else something that returns a graphic, such as:
    return CreateResource("somefile.jpg", "graphic");

    Note that since this is going to be an inline graphic, that is, a graphic that flows inline with text, you need to do this in a Text rule.

  8. 2 hours ago, S_Black said:

    From what I am reading about the ExternalDataFileEx, and correct me if I am wrong, but it is unable to create a new file or add new fields to an existing file.

    If I have a Primary Input and a Secondary data source, the ExternalDataFileEx can update records (SetFieldValue) and save data in either of those files, but it is unable to output a file that contains the fields from both files. Is that correct?

    Correct.  A data source is input, not output.

    Other than the primary composed output, the log (.msg) file, an optional XML log file, and ancillary temp files, a FusionPro composition doesn't write anything to disk.  This is by design, mostly because creating any other files is outside of the intended scope, but also because allowing arbitrary files to be written could be a security issue.

    2 hours ago, S_Black said:

    As an example. The primary input has contact names and a unique business code. The secondary file has the business code and business addresses. I would like to have a single data file with the name from the primary and the addresses from the secondary.

    That seems like something that could be accomplished with a script of some kind, such as PowerShell, Python, VBA, bash, etc.  It's basically a table merge or join in database lingo; apps such as Excel have some functionality like this built in, as do, of course, actual database apps such as Access.  But it's not really in the purview of what FusionPro VDP does directly.

  9. 10 hours ago, AngelBenitez said:

    Hello @Dan Korn; that's what I want to avoid. I don't want to create a rule to depend on another rule. I only want one rule in the rules to achieve the same result.

    Is this possible to do?

    I don't understand your aversion to nested rules, but I suppose if you want to do this all in one rule, then you could just create the "Choose Phone Format" rule with the desired formatting, then convert it to JavaScript, and add any other logic you want.

    • Like 1
  10. If you're in FP 11 or later, then the code you have in that JavaScript rule is fine, and you don't need to make any changes at all to it.  What you need to do is create a new rule, select the "Choose Phone Format" Form Rule, select the name of your JavaScript rule in the "choose field" drop-down list, then select your format.  Then use that form rule in your text frame, and it will format the phone number selected by your script logic.

    • Like 1
  11. This is another "unmaking the soup" kind of thing, but it's doable.  Probably the easiest thing is to just have a list of substitutions to apply to the entire string of text.  And you'll want to use regular expressions to match whole words, and not just replace, say, every E that's part of another word with East.  A regular expression can also be told to match the abbreviation either with or without the trailing dot/period.  Something like this:

    var subs = {
        N: "North",
        S: "South",
        E: "East",
        W: "West",
        Ave: "Avenue",
        Bl: "Boulevard",
        Blvd: "Boulevard",
        St: "Street",
        Ste: "Suite",
        // etc., add more as needed
        };
    
    var address = "512 N Elm Blvd., Ste. 200, Meadowville, NY 12345"; // or Field("Address") etc.
    
    for (var s in subs)
    {
        var re = new RegExp("\\b(" + s + "\\b\\.?)", "g"); // word boundaries, and zero or one dot/period
        address = address.replace(re, subs[s]);
    }
    
    return address;
  12. 51 minutes ago, AngelBenitez said:

    Hello @Dan Korn; thank you for your help. If the value is being pulled from an Excel sheet, what would be the rule to remove the variable in the Excel sheet?

    You would just call the Field function to grab the value from the named data field, for Excel or any other input data format, something like this:

    var s = Field("Title");
    return s.replace(/\s*[IVXL]+$/, '');

    Or if it's from an XDF, something like:

    var s = XDF.GetFieldValue(recordNum, "Title");
  13. var s = "AVP, Digital Media Specialist";
    return s.split(',')[0].replace(/(A?)(VP)/, function(m, A, VP) { return (A ? "Assistant " : "") + "Vice President"; } )

    Or:

    var s = "AVP, Digital Media Specialist";
    var result = s.split(',')[0];
    var parts = result.match(/(A?)(VP)/);
    if (parts)
        result = (parts[1] ? "Assistant " : "") + "Vice President";
    
    return result;


     

  14. This is another one you could Google for, something like "javascript strip roman numerals."

    Assuming that the Roman numerals are at the end of the string, and that they're numbers less than 90, then it's pretty simple:

    var s = "Digtal Media Specialist III"; // field value etc.
    return s.replace(/\s*[IVXL]+$/, '');
  15. This isn't really a question about XDFs specifically, it's just about how to split up a single-field address into multiple lines.

    The good news is that, for questions like this, you can just Google something like "split address in JavaScript" and see lots of examples.

    The bad news is that there's no perfect solution. It's a "how to unmake the soup" question.  Obviously it's better to have the city, state, street, etc. in their own discrete data fields, then you can combine them as needed.  Once they're joined, there's no completely reliable way to split them up.  (It's similar to the problems with un-capitalizing proper names.)

    That said, depending on how consistent the formatting is in the data, something like this should work:

    function splitAddressLines(address)
    {
        var result = address.split(/,\s*/);
        result = result.slice(0, -2).concat(result.slice(-2).join(", "));
        return result.join("\n");
    }
    
    return splitAddressLines("87 Maple Street, Suite 300, Willowdale, CA 90210"); // or a data field, XDF field, etc.

     

  16. Wow, you're on version 7.2?  That's almost 13 years old and out of support.  I don't even remember how much of the current functionality of FusionPro was present back then.

    That said, I think (but don't hold me to it) that there was a version of the ExternalDataFile object that you could invoke via a JavaScript rule in 7.2.   And (I think) you could set FusionPro.Composition.repeatRecordCount in the OnRecordStart rule, and pull data from the ExternalDataFile object based on the repeat number.

    But the easiest thing for you, other than upgrading to a much more recent, and supported, version of FusionPro, may be to simply edit the data file to add a line for each combination of name and date that you want.  It also shouldn't be too hard to write an Excel macro or batch file or some other kind of script to generate that.

  17. On 7/7/2023 at 3:16 PM, DaveYeag said:

    I can't compose onto a slip sheet, right?

    Sure you can.  It's a page of type Template, which is usually used for a repeatable component, but it can still have variable frames when used as a slip sheet.  You'll need a rule that calculates what the start and end record numbers from the chunk will be, but that's not too hard to do, then you can use that rule in a text frame on the slip sheet page.

  18.  

    1 hour ago, sandig199 said:

    I did update my desktop version of Fusion Pro Creator to version 13.0.4. recomposed and uploaded the template files to DSF.

    The result is still missing the overflow page. (attached PDF)

    It's not an issue of the version installed on your desktop.  What gets composed online in DSF is determined by the version of FusionPro Server that's installed on the DSF machine, because it's that FP Server that's doing the composition work.  If version 13 is installed on DSF, then the job will be composed by FusionPro 13, regardless of what version you used to design and upload the template.

    My conjecture is that, at some point, the version of FP Server on the DSF machine was updated, which triggered the difference in the output.  Whatever older version of FP Server that had been on DSF previously was composing differently than the FP 13 that's installed on DSF now.  The way to confirm this is to look at the two different outputs from the online DSF compositions, open them both in Acrobat, and view their Document Properties, which specify the version of FusionPro used for the composition (which may be different than the version used to design the template).

    At any rate, reworking the job to use record repeats rather than overflow pages is probably worthwhile.

     

×
×
  • Create New...