Copy link to clipboard
Copied
OK, try this: Create two read-only text fields, called "InvoiceID1" and "InvoiceID2" and place them one on top of another.
Then add this code as the Mouse Up event of both check-boxes:
if (event.target.value=="0") {
this.getField("InvoiceID1").display = display.visible;
this.getField("InvoiceID2").display = display.hidden;
var prefix = "scd/fds/21/";
var v = Number(this.getField("InvoiceID1").valueAsString.replace(prefix, ""));
if (v==0) v = 5000000;
else v++;
this.getField("InvoiceID1"
...
Copy link to clipboard
Copied
Actually, the subject line doesn't say nearly enough. When should this invoice number update? Does it need to be sequential? Random? Time-based? etc. Does it need to be unique?
A lot of information is missing for us to be able to help you with this.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Are these the check-boxes at the top of the page? So each time they click it should switch pattern? How would it know what was the last number used after the selection was changed? You would need to have two fields, showing/hiding them when each selection is made, and also incrementing their values.
Copy link to clipboard
Copied
Yes, the checkboxes are at the top. it's ok if the number is unique. Not to make things too complicated. but how should I go around that?
I might need to be spoon feed on this. I'm a big-time novice.
thanks
Copy link to clipboard
Copied
OK, try this: Create two read-only text fields, called "InvoiceID1" and "InvoiceID2" and place them one on top of another.
Then add this code as the Mouse Up event of both check-boxes:
if (event.target.value=="0") {
this.getField("InvoiceID1").display = display.visible;
this.getField("InvoiceID2").display = display.hidden;
var prefix = "scd/fds/21/";
var v = Number(this.getField("InvoiceID1").valueAsString.replace(prefix, ""));
if (v==0) v = 5000000;
else v++;
this.getField("InvoiceID1").value = prefix + v;
} else if (event.target.value=="1") {
this.getField("InvoiceID1").display = display.hidden;
this.getField("InvoiceID2").display = display.visible;
var prefix = "scd/hh/21/";
var v = Number(this.getField("InvoiceID2").valueAsString.replace(prefix, ""));
if (v==0) v = 9000000;
else v++;
this.getField("InvoiceID2").value = prefix + v;
}
Copy link to clipboard
Copied
Ok. i would try that and get back to you. thanks.
Copy link to clipboard
Copied
SubhanAllah! it worked.
That's awesome. Thanks a lot. You're a genius
Copy link to clipboard
Copied
One more thing, please!
I want a particular field that would sum up all payments made thus far. that field should be locked from reset. and it would only sum up only when the form is submitted. if the value reaches a particular amount for the form user, the customer should now be discounted 3% of the product bought for the last payment made that hits that programmed target amount. there would also be an uneditable field that shows the target. Normally, he enjoys a 2% discount when he buys with cash and no discount on credit purchases. He/She should also not be able to access any part of the form until they click the cash or credit checkbox. The value vs target field should not add up any credit purchase. The customers are on the drop-down for Key distributors. I guess I have to create many fields on top of the value vs target field for the individual customer just as you helped out on the invoice numbering.
I hope this could be done! the form is attached. Thanks.
Copy link to clipboard
Copied
I don't quite follow... Why do you only want to calculate it when the form is submitted? Why not have it always display the value? Or make it hidden altogether?
Also, I don't understand if you want to apply this discount if the value reaches a certain amount (if so, which one?), or if it's only for certain customers...
At any rate, this is getting a bit more complicated. If you're interested in hiring someone to set it all up for you feel free to contact me privately via [try6767 at gmail.com] and we could discuss it in more detail.
Copy link to clipboard
Copied
The submitted part is not really important. the most important is when the customer reaches the target, then the discount is executed. all the customers are all registered with me. just a growing company I'm working on by the side. want to make it look attractive.
Thanks.
Copy link to clipboard
Copied
You mean you want it to be able to refer to previous purchases (not on this form)? Or is this a calculation that can be done entirely from what the customer typed on this particular form?
Copy link to clipboard
Copied
What the customer typed on this particular form that met the target. The normal 2% discount should now be 3% with an alert congratulating him
Copy link to clipboard
Copied
I think you need to do more than that. Transparency is important, and may be a legal requirement. The customer needs to know exactly what the cost will be - even a surprise discount is not likely to be acceptable. So you need to show the correct discount and total before submitting, not as a surprise (no matter how pleasant).
Copy link to clipboard
Copied
The customers know the discount beforehand. it would be included on the app alert when he clicks on cash purchase field. So he would try to meet that target that would trigger the discount for him. just earlier said, the field would be connected to the customer list on the dropdown.
Copy link to clipboard
Copied
Hello try,
I just transferred this script to another form and changed the prefix to capital letters and is returning NaN. What do I need to change?
Thanks
Copy link to clipboard
Copied
I can't say without seeing the file in question.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I don't see the field where you want this to happen, but the general code is this:
this.getField("Invoice Number").value = util.printf("%06d", Math.floor(Math.random()*1000000));
This will generate a random 6-digit number.