CALLING SCRIPT FROM DOCUMMENT LEVEL NOT RESPONDING

Explorer ,
Aug 15, 2022 Aug 15, 2022

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.

 

 

TOPICS
PDF forms

Views

170

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Check the JavaScript console for errors.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

I CHECKED

this is the message

14:Field: Calculate
ReferenceError: breaks are not defined
14:Field: Calculate

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Where does you use "breaks"?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

See attached

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Where does you use the exact word "breaks"?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

here is the file. sorry I can't remember me using breaks anywhere.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Share a non-secured version of the file, please.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

HERE IT IS.

THANKS

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

I thought about that but have no idea how to combine them. pls guide/show me

Thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

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.

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 15, 2022 Aug 15, 2022

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.


 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2022 Aug 16, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

how do I now use separate date values for each array? I mean how the script should be.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2022 Aug 16, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Okay. that sounds great to me.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

can it be customized to work with mobile phones or pads?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

LATEST

Very unlikely, no. The only mobile app where it might work is PDF Expert by Readdle for iOS devices.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines