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

Function validation drop-down menu

Participant ,
Feb 01, 2023 Feb 01, 2023

Hi
can someone please help me to solve this function?
I inserted this function in the "validation" drop-down menu:

 

if(event.value=="MORTGAGE LOAN"){this.getField("PERSONAL LOAN N").value=this.getField("BANK").value;}
if(event.value=="CREDIT OPENING"){this.getField("PERSONAL LOAN N").value=this.getField("BANK_2").value;}

 

The drop-down menu is called COMMITMENTQEQ
I inserted this function in the calculation script to make the text of the drop-down menu more readable this.getField("COMMITMENT TYPEQEQ").setItems(["MORTGAGE\nMORTGAGE","CREDIT OPENING"]);

When I select the text "OPENING\nCREDIT", the text "MORTGAGE\nMORTGAGE" always appears in the drop-down menu
When I select the text "MORTGAGE\nMORTGAGE", in the menu
the drop-down text always shows "MORTGAGE\nMORTGAGE"

Thank you for your help

TOPICS
JavaScript
1.5K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Feb 01, 2023 Feb 01, 2023

- It's not a good idea to use line-breaks in the items of a drop-down. It's an undocumented "feature", and it's buggy. I would avoid it.

- The strings in your setItems method don't match those in your validation script.

"MORTGAGE LOAN" != "MORTGAGE\nMORTGAGE"

- You have no default value in the Validation script, so when none of the two conditions are true, nothing happens to the target field, basically.

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 ,
Feb 02, 2023 Feb 02, 2023
LATEST

You can execute the script

this.getField("CREDIT").setItems(["CREDIT\nOPENINGS", "MORTGAGE\nLOAN", "PERSONAL\nLOAN"]);

in the Javascript console.

 

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 ,
Feb 01, 2023 Feb 01, 2023

- It's not a good idea to use line-breaks in the items of a drop-down. It's an undocumented "feature", and it's buggy. I would avoid it.

- The strings in your setItems method don't match those in your validation script.

"MORTGAGE LOAN" != "MORTGAGE\nMORTGAGE"

- You have no default value in the Validation script, so when none of the two conditions are true, nothing happens to the target field, basically.

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
Participant ,
Feb 02, 2023 Feb 02, 2023

ok
I'm sorry, I failed to understand one thing.
I have a drop down menu called CREDIT.
In the calculation script I inserted this function:
this.getField("CREDIT"). setItems (["LOAN\nPERSONAL","MORTGAGE\nMORTGAGE","OPENING\nCREDIT"]);
When I go to select from the drop down menu the text
"MORTGAGE
MORTGAGE"
or the text
"OPENING
OF CREDIT",
I always get the text
"LOAN
PERSONAL".

Is there an error in the function, or in these cases does the drop-down menu work like this and it doesn't allow you to bring up the various selected texts?

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 ,
Feb 02, 2023 Feb 02, 2023

When you use setItems it will reset the dropdown to the first entry.

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
Participant ,
Feb 02, 2023 Feb 02, 2023

Okay
Do you have any alternative solutions please?

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 ,
Feb 02, 2023 Feb 02, 2023

Why does you use setItems in a calculation script?

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
Participant ,
Feb 02, 2023 Feb 02, 2023

The drop-down menu field is small and the full text listed in the options menu cannot be read well

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
Participant ,
Feb 02, 2023 Feb 02, 2023

I think I solved the problem this way.
I insert this function in the calculation script of the "CREDIT" menu

this.getField("CREDIT").setItems(["CREDIT\nOPENINGS", "MORTGAGE\nLOAN", "PERSONAL\nLOAN"]);

Then I insert this function in the custom key script of the "CREDIT" field
this.getField("CREDIT").valueAsString.replace(/\n/," ");

Then in the custom validation script of the "CREDIT" field I insert this function

if(event.value == "MORTGAGE\nMORTGAGE")this.getField("PERSONAL LOAN N").value = this.getField("BANK").value;
if(event.value == "CREDIT OPENINGS")this.getField("PERSONAL LOAN N").value = this.getField("BANK_2").value;
if(event.value == "PERSONAL\nLOAN")this.getField("PERSONAL LOAN N").value = this.getField("BANK_3").value;

Finally, I go back to the "CREDIT" field calculation script and delete the function
this.getField("CREDIT").setItems(["CREDIT\nOPENINGS", "MORTGAGE\nLOAN", "PERSONAL\nLOAN"]);
leaving the script empty

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 ,
Feb 02, 2023 Feb 02, 2023
LATEST

You can execute the script

this.getField("CREDIT").setItems(["CREDIT\nOPENINGS", "MORTGAGE\nLOAN", "PERSONAL\nLOAN"]);

in the Javascript console.

 

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 ,
Feb 01, 2023 Feb 01, 2023

When you use setItems it will reset the dropdown to the first entry.

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