Copy link to clipboard
Copied
I try to call the below scripts through the custom calculation field from document-level script with no luck.
what do I do?
function calcTVI() {
var rowNumber = event.target.name.replace("TVI.", "");
var startDateString = "01-08-2022";
var endDateString = "01-09-2022";
var discountedProducts = ["BONUS 6*900G (HDPE)", "BRYTEX WHITE 12*475G", "BRYTEX WHITE 6*900G", "BRYTEX (COLOURS) 12*475G", "BRYTEX (COLOURS) 6*900G"];
var startDate = util.scand("dd-mm-yyyy", startDateString);
var endDate = util.scand("dd-mm-yyyy", endDateString);
var now = new Date();
event.value = "";
var qty = Number(this.getField("QTY."+rowNumber).valueAsString);
var product = this.getField("Products."+rowNumber).valueAsString;
if (discountedProducts.indexOf(product)!=-1) {
if (now.getTime()<startDate.getTime() || now.getTime()>endDate.getTime())
event.value = "N/A";
else if (qty>10)
event.value = Math.floor(qty/10) + " Free Ctns";
}
}
function calcTVIFD() {
var rowNumber = event.target.name.replace("TVI.", "");
var startDateString = "01-07-2022";
var endDateString = "01-08-2022";
var discountedProducts = ["FANCY 48*50G"];
var startDate = util.scand("dd-mm-yyyy", startDateString);
var endDate = util.scand("dd-mm-yyyy", endDateString);
var now = new Date();
event.value = "";
var qty = Number(this.getField("QTY."+rowNumber).valueAsString);
var product = this.getField("Products."+rowNumber).valueAsString;
if (discountedProducts.indexOf(product)!=-1) {
if (now.getTime()<startDate.getTime() || now.getTime()>endDate.getTime())
event.value = "N/A";
else if (qty>20)
event.value = Math.floor(qty/20) + " Free Ctns";
}
}
below is the custom cal script
calcTVI();
calcTVIFD();
Thanks.
Copy link to clipboard
Copied
Check the JavaScript console for errors.
Copy link to clipboard
Copied
I did. below is the response.
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:AcroForm:EmplEmail:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
ReferenceError: breaks is not defined
26:Field:Calculate
SyntaxError: missing ; before statement
1:Console:Exec
undefined
Copy link to clipboard
Copied
I CHECKED
this is the message
14:Field: Calculate
ReferenceError: breaks are not defined
14:Field: Calculate
Copy link to clipboard
Copied
Where does you use "breaks"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Where does you use the exact word "breaks"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Share a non-secured version of the file, please.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Calling both functions from the same field doesn't make sense. The results of the second one will always overwrite those of the first. Why did you split it into two functions?
Copy link to clipboard
Copied
I thought it would work. the promo in most cases runs in Category FOODS & HOUSEHOLD with a different range of free products. FOODS CAN 10:1 HOUSEHOLD MIGHT BE 20:1
Copy link to clipboard
Copied
You have to combine the code to a single function, and then use multiple arrays for the various types of discounts. If the product is not in array1, check array2, etc.
Copy link to clipboard
Copied
I thought about that but have no idea how to combine them. pls guide/show me
Thanks
Copy link to clipboard
Copied
You also have extensive code running as custom calcuation script in all of those dropdown menus that get populated simultaneously with that function.
As soon as I selected one option from the main menu it took very long for the other dropdown fields to populate and almost crashed.
There are better methods to speed up heavy calculations like these, like incorporating custom keystroke scripts, javascript actions, or buttons.
Copy link to clipboard
Copied
I notice that too. The field guys complain about it all the time. please guide me on how to go about that. I am a novice.
Thanks
Copy link to clipboard
Copied
You can use something like this:
var discountedProducts1 = ["BONUS 6*900G (HDPE)", "BRYTEX WHITE 12*475G", "BRYTEX WHITE 6*900G", "BRYTEX (COLOURS) 12*475G", "BRYTEX (COLOURS) 6*900G"];
var discountedProducts2 = ["FANCY 48*50G"];
var isNA = (now.getTime()<startDate.getTime() || now.getTime()>endDate.getTime());
if (discountedProducts1.indexOf(product)!=-1) {
if (isNA) event.value = "N/A";
else if (qty>10) event.value = Math.floor(qty/10) + " Free Ctns";
} else if (discountedProducts2.indexOf(product)!=-1) {
if (isNA) event.value = "N/A";
else if (qty>20) event.value = Math.floor(qty/20) + " Free Ctns";
} // etc.
Copy link to clipboard
Copied
thanks a lot.
should I place the script at the document level or should I put it somewhere else?
thanks
Copy link to clipboard
Copied
And one more thing. The start and end date in most instances are not the same for FOODS & HOUSEHOLD. I notice the script has only one start and end date.
that is why I did what I did initially.
Thanks.
Copy link to clipboard
Copied
- Doc-level is better.
- I thought that might be the case. In that case you would need to use separate date values for each array, and won't be able to use a single variable, like I did with isNA.
Copy link to clipboard
Copied
how do I now use separate date values for each array? I mean how the script should be.
Copy link to clipboard
Copied
Have you ever tried it? We're not really here to write your code for you, but to guide you in doing so.
If you're interested in hiring someone to do it for you, contact me privately to discuss it further.
Copy link to clipboard
Copied
Okay. that sounds great to me.
Copy link to clipboard
Copied
can it be customized to work with mobile phones or pads?
Copy link to clipboard
Copied
Very unlikely, no. The only mobile app where it might work is PDF Expert by Readdle for iOS devices.