Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom script math doesn't work in a forum

Community Beginner ,
Dec 21, 2024 Dec 21, 2024

Hi,
My boss is working on a forum that do math automatically, and one field will divide and multiply  the results at the end.
He has no coding experience at all,  and asked me, I've some knowledge in VB but no idea in Java.
So far I've tried copying some codes in custom script and I can never get any output for the field.

 

v1=this.getfield("Text11").value;

v2=this.getfield("text12").value;
event.value= v1/v2;

But if I write numbers like:
Event.value = 200/5+20;

I get results.
I've no idea about this, please bare with me.

20241219-094057

We're trying to get "Text13" to get the result of dividing "Text11" by "Text12" then multiplied by 70
I know the code should be : Event.value= v1/v2*70;
But I'm just trying to figure why no math would work at all.

Sorry for the image quality, his PC doesn't have access to the internet.
I'll bring a flash drive and upload the file if need to be checked.
Thank you.

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms
880
Translate
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
3 ACCEPTED SOLUTIONS
Community Expert ,
Dec 21, 2024 Dec 21, 2024

You are on the right track, but it's not Java it is JavaScript, and it is case-sensitive so "text12" and "Text12" are not the same, be careful to enter correct field names.

Also, before dividing check that divisor (v2) is not 0, or you will get an error.

Try something like this:

var v1 = Number(this.getField("Text11").valueAsString);
var v2 = Number(this.getField("Text12").valueAsString);

if(v2 !== 0)
event.value = v1/v2*70;
else
event.value = "";

 

View solution in original post

Translate
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 ,
Dec 22, 2024 Dec 22, 2024

It's also getField, not getfield, and event, not Event.

View solution in original post

Translate
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 ,
Dec 26, 2024 Dec 26, 2024

You can try this as 'Validation' script of "Text13" field:

this.getField("Check box16").checkThisBox(0,Number(event.value) > 90 ? true : false);

View solution in original post

Translate
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 ,
Dec 21, 2024 Dec 21, 2024

You are on the right track, but it's not Java it is JavaScript, and it is case-sensitive so "text12" and "Text12" are not the same, be careful to enter correct field names.

Also, before dividing check that divisor (v2) is not 0, or you will get an error.

Try something like this:

var v1 = Number(this.getField("Text11").valueAsString);
var v2 = Number(this.getField("Text12").valueAsString);

if(v2 !== 0)
event.value = v1/v2*70;
else
event.value = "";

 

Translate
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 ,
Dec 22, 2024 Dec 22, 2024

It's also getField, not getfield, and event, not Event.

Translate
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 Beginner ,
Dec 25, 2024 Dec 25, 2024

Sorry for the late reply and my lack of knowledge.
Thank you for clarifying and the extra tip on adding if statment.
My problem was with the letter case sensitive "getfield", I got used to be spoiled with VB autocorrecting me 🙂

Both answers were great and helpful, thank you so much to you both.

I've an extra question my boss asked me if possible to do.
When the same field results > 90, check box will be marked "True".
I don't know how to refer to the fields correctly:
If ("Text13" > 90)
"Check box16".value = True;
?

 Shall I make a new post for this?
Thank you again and I apologize for troublign you with me.

Translate
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 ,
Dec 26, 2024 Dec 26, 2024

You can try this as 'Validation' script of "Text13" field:

this.getField("Check box16").checkThisBox(0,Number(event.value) > 90 ? true : false);

Translate
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 Beginner ,
Jan 04, 2025 Jan 04, 2025
LATEST

Sorry for delay again. You know, holiday and new year 🙂
Happy holidays and new year to you all.

That did the trick Nesa! Bless you.
I can't think you enough, truely, thank you!
Stay awesome and I hope you have a delightful year.

Translate
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