Highlighted
Outstanding Contributor.
Outstanding Contributor.
12170 views

Java script for state form not working


This script doesn't seem to work:

function customLoadCallback() {

var text1 = GetFieldValue("ITEM_DESIGNATION_FOR_SSR_C");

var text2 = IsFieldUnchecked("SOFTWARE_PROMOTE");

alert("text1 = " + text1);

alert("text2 = " + text2);

if (text1 == "SSR" && text2)

SetFieldValue("MOVE_DESIGNATION", " ", "true");

if (text2)

SetFieldValue("MOVE_DESIGNATION", "(No software moved)", "true");

else

SetFieldValue("MOVE_DESIGNATION", text1, "true");

}

AddLoadCallback( customLoadCallback);
0 Likes
12 Replies
Highlighted
Not applicable

Re: Java script for state form not working


lt would help to know what kind of fields you are working with.

Binary/selection, etc..

Also

I would comment out your if and else statements and see if the alerts are pulling your variables corerctly then add your if's back in until you find the problem.

I'm suspect on trying to return a string value into text2 from a binary field

your code is checking if field is checked - true or false not a string but a boolean

Also

you can make your code more efficient by doing the following

if (GetFieldValue("ITEM_DESIGNATION_FOR_SSR_C") == "SSR" + text2);

This way you call the GetFieldValue and check condition at same time, tomatoe - tomato
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


The syntax is

IsFieldChecked

not

IsFieldUnchecked
0 Likes
Highlighted
Not applicable

Re: Java script for state form not working


Yep good catch Brian -

Will there be any issues with loading a binary value into a string? I suppose it would be OK since binary is 1,0 it could still load up into a string..
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


Assuming you used IsFieldChecked above you would probably want to test if the value is false with this syntax

if !(text2)

That should mean "if not text2 true" or is text2 false
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


if !(text2) <--- true, see the problem here?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


Should have said if (! text2)
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


Is the NOT operator is applied to the results of the first clause, not the evaluation of "text2"?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


Funny. the entire rest of my comment just disappeared...

the point was not the placement of the !, but the usage of it.

in Javascript, if a variable is defined (object, discreet value, etc), then if(variable) will return true regardless of the actual value it holds. When checking in a non-strict language (ECMA Script and its descendants), it would be advisable to check the value.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


GetSatisfaction has admitted they have a problem with postings containing code and are working on a solution.
0 Likes
Highlighted
Not applicable

Re: Java script for state form not working


interesting - how will we know when they fix it?
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Java script for state form not working


Good Q. I'm hoping they'll email me. They did to let me know about problem.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.