Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > Getting Started > Sample Jobs

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #21  
Old February 3rd, 2011, 10:50 PM
farns farns is offline
Junior Community Member
 
Join Date: Apr 2010
Posts: 38
Default Re: External Data File Sample - Very Simple Statement

Sorry, one more little bit to add....

it works great on the very last line there where I'm posting "Total =...." I get the dollar sign, the two decimal places... it's just up in the line item part. If I try to apply the FormatNumber, it wipes the value out. I'm guessing a conflict from us stripping those elements out at the top, and the putting it back in at the bottom of the loop, eh?

And copying the rule to other rules to calculate payment plans and discounts worked perfectly. I love this little rule! Just gotta figure out a way to make it work for the cheapskates hahaha

Farns
Reply With Quote
  #22  
Old February 5th, 2011, 07:16 AM
farns farns is offline
Junior Community Member
 
Join Date: Apr 2010
Posts: 38
Default Re: External Data File Sample - Very Simple Statement

I was able to get a stay of execution on this job until Monday. I'm going to keep working on it over the weekend and see if I can figure out what's going wrong, but if there's any chance you read this forum over the weekend Dan, I'd really appreciate any input or direction you can give me on it. Would some screenshots of the results or any other information be helpful in seeing what's up with it?
Reply With Quote
  #23  
Old February 6th, 2011, 08:43 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,297
Default Re: External Data File Sample - Very Simple Statement

Quote:
Originally Posted by farns View Post
it works great on the very last line there where I'm posting "Total =...." I get the dollar sign, the two decimal places... it's just up in the line item part. If I try to apply the FormatNumber, it wipes the value out. I'm guessing a conflict from us stripping those elements out at the top, and the putting it back in at the bottom of the loop, eh?
FormatNumber only works on numbers, not on strings which already contain symbols such as dollar signs. You need to strip those out using logic like where we're adding to the total to convert the field values with the symbols to valid dollar amounts. Something like this:
Code:
returnStr += FormatNumber("$##,###.00", StringToNumber(externalDF.GetFieldValue(recordWalker, 'Price').replace(/[\$,]/g, '')););
Of course, it would be better if the data contained simple numbers and didn't try to pre-format things for you, but it is what it is.

I like to make little convenience functions for these kinds of things. For instance, if you add this code at the top of your rule (or in the JavaScript Globals):
Code:
function NumberFromDollars(text)
{
    return StringToNumber(text.replace(/[\$,]/g, ''));
}

function FormatDollars(text)
{
    return FormatNumber("$##,###.00", NumberFromDollars(text));
}
Then you can simply do this:
Code:
returnStr += FormatDollars(externalDF.GetFieldValue(recordWalker, 'Price'));
Quote:
Originally Posted by farns View Post
PS - I tried to read what I could to understand the ".replace" part of the string to number function... but couldn't find anything. Where can I read up on these things?
The ".replace" is the String.replace function. I'm using it with a regular expression, which is a bit of advanced trickery, but it's all documented here:
https://developer.mozilla.org/en/Jav...String/replace
And here:
https://developer.mozilla.org/en/Jav...Objects/RegExp
Quote:
Originally Posted by farns View Post
Also, same thing for the recordWalker function. Thanks!
That's not a function; recordWalker is simply a variable used in a for loop. It could just as easily be named "r".
https://developer.mozilla.org/en/Jav...Statements/for
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; February 6th, 2011 at 08:51 PM.. Reason: explain "for" loop
Reply With Quote
  #24  
Old February 6th, 2011, 08:46 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,297
Default Re: External Data File Sample - Very Simple Statement

By the way, here's my updated version of the rule from the sample job:
Code:
function NumberFromDollars(text)
{
    // Strip dollar signs and commas to convert the value to a number for math.
    return StringToNumber(text.replace(/[\$,]/g, ''));
}

function FormatDollars(text)
{
    return FormatNumber("$##,###.00", NumberFromDollars(text));
}

if(FusionPro.inValidation)
    Rule("OnJobStart");

var returnStr = "";
var total = 0;

for (var r = 1; r <= externalDF.recordCount; r++)
{
    // Convenience function to simplify code below.
    function ExDataField(name) { return externalDF.GetFieldValue(r, name); }

    //Compare the value of the CID field in the current record
    //we are looking at in the external data file to the value
    //of the CustomerID field in the main data file.
    if (ExDataField('CID') == Field("CustomerID"))
    {
        var product = ExDataField('Product-Purchased');
        var price = ExDataField('Price');
        
        //Check to see if this is a TAX item.  If it is, let's format it differently
        if (product == 'Tax')
            returnStr += '<br>\n<b>Total Tax - ' + FormatDollars(price) + '</b>';            
        else //OK - so this is a normal product - not a Tax item
            returnStr += product + ' - ' + FormatDollars(price) + '<br>\n';

        total += NumberFromDollars(price);
    }
}

return returnStr + "<br><br>\n\nTotal purchase: " + FormatNumber("$0.00", total);
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #25  
Old February 8th, 2011, 07:50 AM
farns farns is offline
Junior Community Member
 
Join Date: Apr 2010
Posts: 38
Default Re: External Data File Sample - Very Simple Statement

Thanks so much Dan! This all made good sense, and the adjustment made everything work perfectly. I just thought it was odd that it worked on everything over $1000, but nothing under. I suppose there's a logical reason, if one understands the code better... LOL...

I'm curious why this forum doesn't arrange the responses chronologically? It's almost like different responses break off and start their own thread or something. I kept refreshing the original post, but you can't see many of the replies without clicking that link that says "more posts deeper than this" or something like that. Your answer had been sitting there forever before I found it, because it was branched off in another direction. I've been on a lot of forums but never seen one behave like this. What's the secret to being able to follow these threads more intelligently?

Thanks again for all your help on this!!

Farns
Reply With Quote
  #26  
Old February 8th, 2011, 09:30 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,297
Default Re: External Data File Sample - Very Simple Statement

Quote:
Originally Posted by farns View Post
I'm curious why this forum doesn't arrange the responses chronologically? It's almost like different responses break off and start their own thread or something. I kept refreshing the original post, but you can't see many of the replies without clicking that link that says "more posts deeper than this" or something like that. Your answer had been sitting there forever before I found it, because it was branched off in another direction. I've been on a lot of forums but never seen one behave like this. What's the secret to being able to follow these threads more intelligently?
Near the top of any thread, there's a bar with items including "Thread Tools", "Search this Thread", "Rating", and "Display Modes". Click on "Display Modes" and select "Switch to Linear Mode."

More info here:
http://forums.printable.com/faq.php?...thread_display
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; February 8th, 2011 at 02:16 PM.. Reason: Link to forum FAQ re: Thread Display Options
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 08:28 AM.


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