Copy link to clipboard
Copied
The first dropdown is called "Key_Distributors" with the following list (-SELECT-, PAT-SONNY NIGERIA ENTERPRISES, EVANS MAC BUSINESS VENTURES LTD, HAYAT INTERGRATED SERVICES LIMITED (Abuja), ALHAJA KOLAWOLE NIGERIA ENTERPRISES, DAM-LIZZY VENTURES, HAPPY PLACE INTERNATIONAL,)
The second dropdown is called "Category" with the following list (-SELECT-, Foods, Household, Nastrade)
The two fields to display values dependant on the the two dropdown fields are called "Credit_Limit & Customer_Code"
for example If PAT-SONNY NIGERIA ENTERPRISES and Foods are select from the dropdowns, below is what should be displayed.
"Credit_Limit" field to display 1000, "Customer_Code" field to display 100222
If PAT-SONNY NIGERIA ENTERPRISES and Nastrade are select from the dropdowns, below is what should be displayed.
"Credit_Limit" field to display 2000, "Customer_Code" field to display 15022
If EVANS MAC BUSINESS VENTURES LTD and Household are select from the dropdowns, below is what should be displayed
"Credit_Limit" field to display 4000, "Customer_Code" field to display 110033.
similarly with the other dropdown list.
I hope this could be done.
thanks in anticiption for a quick response
Here's the basic syntax to use (for the Credit_Limit field, in this case):
var v1 = this.getField("Key_Distributors").valueAsString;
var v2 = this.getField("Category").valueAsString;
if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Foods") event.value = 1000;
else if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Nastrade") event.value = 2000;
// etc.
else event.value = "";
Add all the values where it says // etc., using the same format, and then adjust the script for the other field, too.
Kee
...Copy link to clipboard
Copied
Here's the basic syntax to use (for the Credit_Limit field, in this case):
var v1 = this.getField("Key_Distributors").valueAsString;
var v2 = this.getField("Category").valueAsString;
if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Foods") event.value = 1000;
else if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Nastrade") event.value = 2000;
// etc.
else event.value = "";
Add all the values where it says // etc., using the same format, and then adjust the script for the other field, too.
Keep in mind, though, that JS is case-sensitive, so if the value is "FOODS" then you must write it like that in your code, as "Foods" won't work, and vice versa.
Copy link to clipboard
Copied
i adjusted the script as this:
var v1 = this.getField("Key_Distributors").valueAsString;
var v2 = this.getField("Category").valueAsString;
if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Foods") event.value = 1000;
else if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Household") event.value = 2000;
else if (v1=="PAT-SONNY NIGERIA ENTERPRISES" && v2=="Nastrade") event.value = 3000;
if (v1=="EVANS MAC BUSINESS VENTURES LTD" && v2=="Foods") event.value = 4000;
else if (v1=="EVANS MAC BUSINESS VENTURES LTD" && v2=="Household") event.value = 6000;
else if (v1=="EVANS MAC BUSINESS VENTURES LTD" && v2=="Nastrade") event.value = 5000;
if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2=="Foods") event.value = 4000;
else if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2=="Household") event.value = 4000;
else if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2=="Nastrade") event.value = 4000;
if (v1=="ALHAJA KOLAWOLE NIGERIA ENTERPRISES" && v2=="Foods") event.value = 1000;
else if (v1=="ALHAJA KOLAWOLE NIGERIA ENTERPRISES" && v2=="Household") event.value = 1000;
else if (v1=="ALHAJA KOLAWOLE NIGERIA ENTERPRISES" && v2=="Nastrade") event.value = 1000;
if (v1=="DAM-LIZZY VENTURES" && v2=="Foods") event.value = 6000;
else if (v1=="DAM-LIZZY VENTURES" && v2=="Household") event.value = 7000;
else if (v1=="DAM-LIZZY VENTURES" && v2=="Nastrade") event.value = 3000;
if (v1=="HAPPY PLACE INTERNATIONAL" && v2=="Foods") event.value = 6000;
else if (v1=="HAPPY PLACE INTERNATIONAL" && v2=="Household") event.value = 7000;
else if (v1=="HAPPY PLACE INTERNATIONAL" && v2=="Nastrade") event.value = 3000;
else event.value = "";
and placed it the "Credit_Limit" custom calculation script but nothing was displayed. i guess i didnt adjust it properly. pls help look at it again for corrections.
Thanks.
Copy link to clipboard
Copied
It will only calculate last 'if' condition for 'HAPPY PLACE INTERNATIONAL'.
Put 'else if' on all condition, leave only first one 'if'.
Copy link to clipboard
Copied
I Really feel at home. Thanks to you all for your help.
My rain drops are gradually becoming an ocean in the work place. bosses and colleagues are feeling safe over the path i'm leeding them through. and its all because of you guys.
Thanks a lot.
Copy link to clipboard
Copied
Nesa's comment is correct. Also, you can also simplify parts of your code. For example this part:
if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2!="Foods") event.value = 4000;
else if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2=="Household") event.value = 4000;
else if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2=="Nastrade") event.value = 4000;
In this case the second value doesn't matter, since it will always be 4000, so you just want to make sure it's not the default value. So you can replace that whole part with just this:
else if (v1=="HAYAT INTERGRATED SERVICES LIMITED (Abuja)" && v2!="-SELECT-") event.value = 4000;
Copy link to clipboard
Copied
I just tried that. Worked perfectly.
Thanks
Copy link to clipboard
Copied
I have another similar request.
Let's say I am running a promo on these products from a dropdown ("CORNFLAKES ORIGINAL 36*35G", "ACTION 10*1KG", "ASSORTED CREAM BISCUIT 48*44G", "FROSTED FLAKES 10*350G",)
With this promo, when you buy 10 cartons upward; you get 1 free carton for every 10 cartons within a timeframe.
for example, I am to run this promo from 07-06-2022 to 05-07-2022, I want when a buyer selects any of the above lists of product and type in 99 or any figure on the "QTY" field, it should calculate and display the number of ctns you get from dividing the "QTY" value he imputed by 10 with a suffix of "free" on a field labeled "TVI". And when the promo deadline reaches, it should display N/A. This means the "QTY" & those product lists from the "Products" dropdown field would always be looking at the "Current_Date" field to determine what gets displayed on the "TVI" field.
I really hope this can be done.
Thanks a lot.
Copy link to clipboard
Copied
It's possible, but making it dependent on a date is tricky. Should it rely on the computer date, or on a date entered into the form? If the former, the user will just be able to change the date on their computer to get the free items... Also, what if they fill it in during this period, but send it to you afterwards? etc.
Copy link to clipboard
Copied
I want it to depend on the computer date. i thought of those possibilities. i am to as well use the date the form was sent back to my mail to justify if the person qualifies for it. thus, if the person changes the date on his computer, i'll still look at when he submits it.
Thanks.
Copy link to clipboard
Copied
Try this code, as the custom calculation script of "TVI":
event.value = "";
var startDateString = "07-06-2022";
var endDateString = "05-07-2022";
var startDate = util.scand("dd-mm-yyyy", startDateString);
var endDate = util.scand("dd-mm-yyyy", endDateString);
var now = new Date();
var qty = Number(this.getField("QTY").valueAsString);
if (now.getTime()<startDate.getTime() || now.getTime()>endDate.getTime())
event.value = "N/A";
else if (qty>10)
event.value = Math.floor(qty/10) + " free";
Copy link to clipboard
Copied
Okey.
Thanks a lot.
from the code I noticed my mistake in expression. what I didn't mention is the dropdown has other lists of products from the dropdown. the ones I mentioned are just a few from the whole list of dropdowns. the request from the buyer might include other products. the display on free cartons should be based on the ones the promo is on. e.g., my list of products might be from A - Z but the promo is on B, C, & D
Thanks for everything thus far.
Copy link to clipboard
Copied
Sorry, I don't quite follow what you mean... It would be easier to help you if I could see the actual file.
Could you share it, perhaps?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think I understand. You can do it like this, then:
var startDateString = "07-06-2022";
var endDateString = "05-07-2022";
var discountedProducts = ["ASSORTED CREAM BISCUIT 36*100G", "CORNFLAKES ORIGINAL 10*350G", "DELIGHT COOKIES 16*120G"]; // replace with actual product names
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.0").valueAsString);
var product = this.getField("Products.0").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";
}
Copy link to clipboard
Copied
perfect!!!!!
This is exactly what I wanted.
Thanks a million times
Do I have to repeat the script for all the rows?
just in case he selects the product in a different row. I'm asking because I would be making a column for the TVI withing the table.
Copy link to clipboard
Copied
It's possible to convert it into a generic function and call it from each field, passing the row number as an input parameter, assuming the list of discounted products is the same for all rows.
Copy link to clipboard
Copied
That would be perfect for me. pls, show me how.
Thanks.
Copy link to clipboard
Copied
Actually, you don't even need to pass that parameter. Place this code as a doc-level script:
function calcTVI() {
var rowNumber = event.target.name.replace("TVI.", "");
var startDateString = "07-06-2022";
var endDateString = "05-07-2022";
var discountedProducts = ["ASSORTED CREAM BISCUIT 36*100G", "CORNFLAKES ORIGINAL 10*350G", "DELIGHT COOKIES 16*120G"]; // replace with actual product names
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";
}
}
And then just call it from the fields, like this:
calcTVI();
Copy link to clipboard
Copied
I really don't know how this works but when you say place this calcTVI();. is it in the custom cal. field?
Copy link to clipboard
Copied
Correct.
Copy link to clipboard
Copied
I'll do just that.
I sincerely appreciate all the time and suggestions you've given me thus far. I really learned a lot.
Thanks again
Copy link to clipboard
Copied
I need a little help with the attached form.
Now that we are trying to put the form to use, we realize the discount calculation base on the radio button click is not working properly unless you click it more than once before it does the discount calculation. and when you select another product it would not calculate the discount until you click it again.
Thanks in anticipation.
Copy link to clipboard
Copied
You need to fix the fields calculation order, so that the Discount field is calculated after the Amount fields and Total Amount.
Copy link to clipboard
Copied
I just arranged it and cleared the form. I still get the same result.