mubangud Absent Member.
Absent Member.
7450 views

Setfieldvalue based on text from a single relational field


I am trying to figure out the simplest JavaScript syntax to use that will allow for the options from a single relational field to change the options in a single selection field.

For example

Single ration field A: L1,L2,L3,H1,H2,H3

Single selection field B: Low, High

If (A==L1,L2,L3) then set field value of field B to Low

Else if If (A==H1,H2,H3) then set field value of field B to High

So this script basically just needs to look at the value of one field and set the value value in another field to reflect a consolidated result. I'm just to sure how to place the multiple OR without having to write it in a long form.
0 Likes
4 Replies
Highlighted
mubangud Absent Member.
Absent Member.

Re: Setfieldvalue based on text from a single relational field


I figured out the solution on my own. So what I was doing wrong with my selection was not placing the "||" between each or statement. The script comes to something like below but is there a simpler version to accomplish this?

AddLoadCallback (PrioritySummary);

function PrioritySummary()

{

var priorityvalue = GetFieldValue("PRIORITY");

var prioritysum = GetFieldValue("PRIORITY_SUMMARY");

if (priorityvalue == "(None)")

{

SetFieldValue("PRIORITY_SUMMARY", "None");

}

else if (priorityvalue == "C1")

{

SetFieldValue("PRIORITY_SUMMARY", "Critical");

}

else if (priorityvalue == "H1"||priorityvalue == "H2"||priorityvalue == "H3"||priorityvalue == "H4"||priorityvalue == "H5"||priorityvalue == "H6"||priorityvalue == "H7")

{

SetFieldValue("PRIORITY_SUMMARY", "High");

}

else if (priorityvalue == "M1"||priorityvalue == "M2"||priorityvalue == "M3"||priorityvalue == "M4"||priorityvalue == "M5"||priorityvalue == "M6"||priorityvalue == "M7")

{

SetFieldValue("PRIORITY_SUMMARY", "Medium");

}

else if (priorityvalue == "L1"||priorityvalue == "L2"||priorityvalue == "L3"||priorityvalue == "L4")

{

SetFieldValue("PRIORITY_SUMMARY", "Low");

}

}

function PageLoad()

AddChangeCallback(PrioritySummary);

AddChangeCallback("PRIORITY", PrioritySummary);

AddChangeCallback("PRIORITY_SUMMARY", PrioritySummary);
0 Likes
abrowning Absent Member.
Absent Member.

Re: Setfieldvalue based on text from a single relational field


if (priorityvalue.substring(0,1) = "H")

the substring method lets you extract part of a string. The substring starts at 0. The substring stops at location 1.

You could also do something like:

switch (priorityvalue.substring(0,1) )

{

case "H":

SetFieldValue("PRIORITY_SUMMARY", "High");

break;

case "C":

SetFieldValue("PRIORITY_SUMMARY", "Critical");

break;

case "M:

SetFieldValue("PRIORITY_SUMMARY", "Medium");

break;

case "L":

SetFieldValue("PRIORITY_SUMMARY", "Low");

break;

default:

SetFieldValue("PRIORITY_SUMMARY", "None");

}
0 Likes
mubangud Absent Member.
Absent Member.

Re: Setfieldvalue based on text from a single relational field


on thing I am noticing is that the records, previously submitted, all changed to to correct settings but when I ran my report my priority summary field is still showing up as "(None)" in the report. The only way I have been able to correct this is to perform an update on each record and save. The problem with this is that it is going to take a long time to do this for all the records in the system.

Any ideas why reports aren't displaying correctly even when the javascript sets the value?
0 Likes
jeff_malin Absent Member.
Absent Member.

Re: Setfieldvalue based on text from a single relational field


Alan's answer is the best for your situation, but if you had values which weren't easily parsed using .substring(), you can also use the Javascript "In" operator, like

if (color in {red:0, green:0, blue:0} ) {

do something;

};

See: http://snippets.dzone.com/posts/show/.
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.