Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

how do you assign script (uppercase/sentence case) output to a variable?

Avatar

Level 4

Hi, I posted a question and a forum user Raghu was really great, and helped to get a working demo going, but i'm still a bit lost

the demo form is attached, and as you can see Raghu has some cool code on the variables to make stuff go ALL CAPS and Sentence caps, which is what we need, and you can see that it works cause it is output to the text fields and appears correctly.

Now thats cool, i suspect were 90+ % of the way there, but what i dont know how to do is to have the input text (the name fields rawValue) turned into variables so i can use them without first putting them into fields and referencing those

Raghu kindly explained that this could be done by calling it as a function, (and no doubt he's right) but i don't know how to do that.....

can anyone clarify, ideally with an idiot proof example or two

I need to be able to attach the code/call the function to about 20 fields in each form, and have a variable for each of those fields, like so

First Name Field      - rawvValue entered  " Julia"  

Middle Name Field   - rawValue entered "katie"

Last name field -      - rawValue entered "smith"

to get 6 vars that i call call directly ie FNUpper (for JULIA) FNSC (for Julia) MNUPPER (for KATIE) and so on

anyone out there able to explain/demonstrate this in idiot proof lingo?

thanks for the help

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Greg,

There are two types of variables (as far as I know). The first is a script variable, which you create in your script using the "var" function. Once you have created / declared it in the script, you can refer to it by its name. The str above is an example.

The second is a global variable, which is created and declared in the File / Form Properties / Variable tab. Once you have created a global variable you do not need to create it again in the script. In fact once you have created the global variable, you can see them in the hierarchy under variables. When you reference these in script you need to use the .value property in order to set and retrieve the contents of the global variable.

So the script would look something like this:

var str = this.rawValue;

try{

     if(!js.isEmpty(this.rawValue))

     {

          fnUP.value = js.allUpper(str);

     }

}

catch(e){app.alert(e)}

Sample attached. The two extra field are just displaying the current value of the global variables. Also test this solution, because (even with the form set to automatic saving of script changes) the global variables may revert to the defaults when reopened.

Good luck,

Niall

View solution in original post

11 Replies

Avatar

Level 10

Hi,

You were nearly there, see script attached calling the function. It is a very nice solution from Raghu.

I don't think you need to go need global variables. You just need to call the appropriate function in each field's exit event depending on whether you want uppercase or sentence case.

Good luck,

Niall

Avatar

Level 4

Hi Niall,

Thanks for that. The reason i'm trying to go to global variables is I won't actually be displaying the output onscreen i will be using the variables to enable me to produce output that then go a custom back end process.

so you end up with code like

switch (this.rawValue) {

     case "1":

     {output.rawValue =  A1.value + a3.value + FirstNameUppercase (this is where i need help)  + " " + LastNameSentenceCase (help) + A2.value}

          break;

     case "2":

to produce an output field containing a text string that is responsive to user selections (above just a crude demo of course)...

hence the need for Upper and Sentence case variables output from each of the various peoples who's names are collected etc.....

so that would permit the above code to be reduced to

  case "1":

     {output.rawValue =  A1.value + a3.value + say we call the variable clientFNUC + " " + clientLNSC + A2.value}

          break;

     case "2":

ie there will never be a box that displays this data just a post from the input raw.value to a variable which is integrated into various hidden output fields that go off for back end processing....

thanks for the help

Avatar

Level 10

Sorry, wrong end of the stick!!

I would be inclined to call the functions and assign the global variables in one step and then concatenate them in FormCalc.

I am not sure if I would include two function calls within a calculation. Not saying it can't be done, but you may want to test it first by sending the result to a textfield first where you can see the results during testing.

The only thing in your mockup of the script is that you appear to be missing the name of the script object (js.). Also if your script object is off the main node path, you may need to include a full SOM.

Try the javascript console to see what is going on when previewing.

Hope you get it running,

Niall

Avatar

Level 4

Hi Niall,

the multiple a1.value + A3.value  + etc is working fine (using java)

I just have absolutely no idea HOW to call the function Raghu provided and assign the two outputs (UC and SC) to the variables so they can be reused.... thats my point of confusion (for today at least !)

thanks

greg

Avatar

Level 10

Hi Greg,

If you look at the previous version (albeit was not waht you wanted) the following line is calling the function:

this.rawValue = js.allUpper(str);

The syntax is nameOfScriptObject.nameOfFunction(variableToPassToFunction). eg js.allUpper(str)

In your case the script object is called "js". One of the functions in this script object is called "allUpper". Your particular function needs just one piece of information from the form, this is passed through by the "str" variable which is declared earlier in the script.

In your previous post, you appeared to be missing the name of the script object in your call.

Hope that helps,

Niall

Avatar

Level 4

Niall,

Thanks that's much clearer;

so to take a field (FirstName) in which you have data "sarah" to uppercase and lowercase,

on the exit event for "firstname" would you then be able to go something like....

var str = this.rawValue;

try{

if(!js.isEmpty(this.rawValue))

{

var FirstNameUpper = js.allUpper(str);

var FirstNameSC = js.firstCharUpper(str);}

}

catch(e){app.alert(e)}

to arrive at two var's you could call in the a1 + b3 + FirstNameUpper + a2 style ?
sorry if i'm being dumb (code is still quite new to me....) but when/how you would assign that var escapes me....
or can you just use js.firstname.rawValue.allUpper (or similar) to where you need this - it's the syntax to put it to a var or call it that has me baffled....
thanks 

Avatar

Correct answer by
Level 10

Hi Greg,

There are two types of variables (as far as I know). The first is a script variable, which you create in your script using the "var" function. Once you have created / declared it in the script, you can refer to it by its name. The str above is an example.

The second is a global variable, which is created and declared in the File / Form Properties / Variable tab. Once you have created a global variable you do not need to create it again in the script. In fact once you have created the global variable, you can see them in the hierarchy under variables. When you reference these in script you need to use the .value property in order to set and retrieve the contents of the global variable.

So the script would look something like this:

var str = this.rawValue;

try{

     if(!js.isEmpty(this.rawValue))

     {

          fnUP.value = js.allUpper(str);

     }

}

catch(e){app.alert(e)}

Sample attached. The two extra field are just displaying the current value of the global variables. Also test this solution, because (even with the form set to automatic saving of script changes) the global variables may revert to the defaults when reopened.

Good luck,

Niall

Avatar

Level 4

Niall,

That works perfectly.

Thank you (once again) for the help (and patience with newbie errors).

Cheers !

Avatar

Level 2

Hi.  I see this is an older post but it's right on the road of what I need.  I can get the all caps to work for the text fields, but I am trying to see if there is a way to do the same thing to a "date field" so that the dates won't default to first letter cap only.

What I have is a form with floating fields that are bound to text, date, dropdown fields etc..  Everything so far is working the way I want, i just need to see if there is a way to fix the date to all caps or if I need to just switch to dropdown list.

Thanks in advance.

Avatar

Level 10

Hi,

This should get you out of the blocks:

var vDate = DateTimeField1.formattedValue;

this.rawValue = vDate.toUpperCase();

Sample here: https://acrobat.com/#d=5Vboe3SIXWnshmnlRa0NZw

Hope that helps,

Niall

Avatar

Level 2

That did the trick wonderfully.  Thanks again.