Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 2nd, 2019, 10:54 AM
Carrie Dodt Carrie Dodt is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 18
Default Have to have exact number in a field.

I have a field which requires 6 numbers.
If they put in less than 6 it goes thru. Is there a rule that will return an error of less than 6 number is input?


thank you!
Reply With Quote
  #2  
Old October 2nd, 2019, 01:11 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,359
Default Re: Have to have exact number in a field.

You can certainly use JavaScript to validate that a particular string (such as the value of a data field) meets certain criteria. A "brute force" way would be something like this:
Code:
var s = Field("YourFieldName");
if (s.length != 6)
    return "invalid data; must be 6 characters";
//else
for (var i in s)
{
    if (s[i] != '0' && Int(s[i]) == 0)
        return "invalid data; must be all numbers";
}
//else
return "OK";
However, that's not very succinct code. JavaScript, especially with its very powerful Regular Expression functionality, is actually great for this doing kind of data validation, without having to write so much code, and many web pages use JavaScript validation logic for web form entries.

The most JavaScript-y way to check that a string consists of exactly 6 numbers (digits) to try to match it against the Regular Expression /^\d{6}$/ , which means "between the start (^) and end ($) of the string, exactly 6 digits (\d)". So you could use that in a rule like so:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    return "invalid data";
//else
return "OK";
But the tricky part, in terms of a FusionPro job, is what you mean by "return an error." If the place where the end user is entering this data is in another application, such as a web form (in MarcomCentral or a different application), then any logic to return an error message to the user at data entry time (like popping up a message box) would have to be part of that other application.

At composition time, in FusionPro, there are a few things you can do to either denote an error in the output, or to prevent generation of the output in the first place, if the input data is not valid. The simplest is probably something like this:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    return '<span color="Red">Invalid entry in field "YourFieldName"; value must be exactly six digits.</span>';
//else
return TaggedDataField("YourFieldName");
That would show the error message, in Red, in place of the field value, in the output.

Another thing you could do is write a message to the composition log (.msg) file, like so:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    Print('Error: Invalid entry in field "YourFieldName"; value must be exactly six digits.';
If you want to, say, have the entire composition error out if the entry is invalid, you could do this:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    FusionPro.Composition.Abort('Error: Invalid entry in field "YourFieldName"; value must be exactly six digits.');
Or, if you just want to skip that particular record of data in a VDP job, but still let other records compose and make output:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    FusionPro.Composition.Abort('Error: Invalid entry in field "YourFieldName"; value must be exactly six digits.', true);
(Where the "true" parameter means "skip this record only, instead of aborting the whole job.")

These are just a few of the ways in which you can handle the error condition, where the data field doesn't meet the criteria. But you can really do whatever you want, depending on your workflow.

So to recap, testing a field value to make sure it conforms to a particular pattern is pretty straightforward, and JavaScript is great for doing that, but what's not so straightforward is exactly how you want the error condition of the data not conforming to the pattern to be handled, and how that should be expressed to a user at some step in your job's workflow of data entry through composition.
__________________
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
  #3  
Old October 2nd, 2019, 03:46 PM
Carrie Dodt Carrie Dodt is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 18
Default Re: Have to have exact number in a field.

Thanks very much for your help. I did get an error message to return, however can I change that message to say: "Six digits must be input for the Cost Center."
Attached Images
File Type: jpg Screenshot 2019-10-02 16.26.59 copy.jpg (108.0 KB, 6 views)
Reply With Quote
  #4  
Old October 2nd, 2019, 04:30 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,359
Default Re: Have to have exact number in a field.

Quote:
Originally Posted by Carrie Dodt View Post
Thanks very much for your help. I did get an error message to return, however can I change that message to say: "Six digits must be input for the Cost Center."
Okay, so this gives me a bit more information, but still leaves some out.

What I can see from your screenshot, which was not obvious before, is that you're asking specifically about showing an error message in the context of the MarcomCentral application, where the user fills out the form and sees the template preview.

First of all, I believe there is a way to set up validation on those input fields on the form in MarcomCentral, so that you get a message right there on the form, before a FusionPro composition even takes place. That's a question for the MarcomCentral application forum.

That said, what your post leaves out is exactly which of the suggestions in my previous post you tried. I assume it's the one that calls FusionPro.Composition.Abort() to prevent any output from being generated at all.

If you instead want to make output, but have it show a more specific message, so that the message appears on that MarcomCentral preview, that's basically what my first suggestion was:
Code:
if (!Field("YourFieldName").match(/^\d{6}$/))
    return '<span color="Red">Invalid entry in field "YourFieldName"; value must be exactly six digits.</span>';
//else
return TaggedDataField("YourFieldName");
Though if you want something more "in your face," you could just make a giant text frame that covers the whole page, with that message in it, and have a rule slightly different than the one above to show a message if the validation fails, or nothing at all if it succeeds:
Code:
if (!Field("Cost Center").match(/^\d{6}$/))
    return 'Six digits must be input for the Cost Center.';
//else
return '';
Then put that rule into the giant text frame, with no frame fill, at the top layer, in 200 point red text or something. When the input is okay, you'll see nothing in that frame, but if it's not okay, the error message will appear.

Another option is to make a frame with the error message text typed into it, with a frame fill color (probably white), name that frame, then in OnRecordStart, selectively show or hide the frame:
Code:
FindTextFrame("Error Message Frame").suppress = !Field("Cost Center").match(/^\d{6}$/));
Again, when the input is okay, that frame will be suppressed, but if it's not, it will show up and cover the other content on the page.

There are a lot of other similar things you could do. But, like I said at at the start, I'm pretty sure there's a way to do the validation in MarcomCentral, and not have to have it fall to FusionPro at all.
__________________
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
  #5  
Old October 2nd, 2019, 06:21 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,359
Default Re: Have to have exact number in a field.

So again, you should ask about this in the MarcomCentral app sub-forum, or Service Desk, or ask your CPM/BRM/support person, because I'm not an expert in how to set up a template there. But, in the admin tool, under Template Setup, under the Form Display tab, you can click on the field name to edit the a data field, and then under "Configure Custom Form Validation Rule," you can set up the validation code for that field. The idea here is that the data entry validation happens on the web form, before the job even tries to preview in FusionPro.



Once again, though, for exactly what you need to type in there, you should ask on the MarcomCentral forum, or Service Desk, or contact your CPM or MarcomCentral Support.
Attached Images
File Type: jpg MCC-field-config.jpg (72.6 KB, 25 views)
__________________
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
  #6  
Old October 3rd, 2019, 09:51 AM
Carrie Dodt Carrie Dodt is offline
Junior Community Member
 
Join Date: Sep 2008
Posts: 18
Default Re: Have to have exact number in a field.

Thank you again, for all your time and effort with this. Yes, it would be best to validate in Marcom Central, as I have at least 20 templates requiring this. I have gone thru what you are sending, and it all appreciated!
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 09:59 PM.


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