Skip to main content
davidr41478633
Participating Frequently
May 25, 2018
Answered

Is there an easier way to write this script?

  • May 25, 2018
  • 3 replies
  • 545 views

I am working on a custom format script for a dropdown field and i keep getting an error that the script is to long for the dialog box. I am fairly new to this and I think there is a way to write the script below to save time and space. This is just a sample of the entire script.

var f = event.target;var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("Caption1").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("Caption1").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("Caption1").value = "XX Removal\nDate:\nTotal Acres";

var f = event.target;

var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("Caption2").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("Caption2").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("Caption2").value = "XX Removal\nDate:\nTotal Acres";

var f = event.target;var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("TEXT").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("TEXT").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("TEXT").value = "XX Removal\nDate:\nTotal Acres";

This topic has been closed for replies.
Correct answer gkaiseril

Change the default built-in editor to an external text editor. Text editors are not Word or other word processing program. Examples are Textpad or Notepad plus.

3 replies

Inspiring
May 25, 2018

If you are trying to see if required fields have been completed, there are other ways that include looping through the fields and testing the "required" property's value and then testing to see if the current value is that same as the field's default value and setting a control flag for later processing or adding the field name to an array of incomplete fields. The number of lines for this type of solution remains the same no matter how many fields are in the form.

try67
Community Expert
Community Expert
May 25, 2018

You can shorten your code by using variables. Instead of referring to the same field multiple times like this:

this.getField("Caption1").value = ...

Change it to:

var f1 = this.getField("Caption1");

f1.value = ...

gkaiserilCorrect answer
Inspiring
May 25, 2018

Change the default built-in editor to an external text editor. Text editors are not Word or other word processing program. Examples are Textpad or Notepad plus.