Absent Member.
Absent Member.
3173 views

I want to read checl values in a multirelational field and make corresponding date values required or optional.

I have a multi-relational field that has about 20 checkboxes. When the Development checkbox is checked I want another field called "Development Date" to become required.

I already have some code that is reading through the list to hide unchecked check boxes but I don't think it reads the checkbox field names. Looks like it's only reading the array index and whether it's checked. If it could also read the Checkbox name it would possibly make this easy, then I could just have if statements like:

If "Development" is checked Make "Development" Date required.

I guess I need to read up on my javascript....

This is the code I have (thanks to the forum) that hides the checkboxes:

if (GetFieldWidgetByName) {
var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:not(:checked)");


for (i = 0; i < x.length; i++)
{
$(":[value='"+ x.value +"']").hide();


// $(":[value!='"+ x.value+"']").checked = false;

}
}


Thinking about this some more, looks like it would have to read the aux table to get the field name value...

//Change the code to only read checked values.
if (GetFieldWidgetByName) {
var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:(checked)");


for (i = 0; i < x.length; i++)
{


$(":[value='"+ x.value +"']"). (Go to aux table and get name value based on index)


If the Name is Development
{
MakeFieldRequired("Development Date");
}

// $(":[value!='"+ x.value+"']").checked = false;

}
}


Can this be done in javascript? If yes, any examples?

Regards,

Will
0 Likes
5 Replies
Absent Member.
Absent Member.

Will,

See how this works.

jQuery is a good thing to take a look at as it is just javascript on steroids. It was created to just make a lot of things you do with basic javascript much easier.

I would keep your original form action because that hides all the non-checked and then create another form action that runs on load after the first one that does the following. So let's assume you have a checkbox called Development and one called Production and one called UAC. The following code just assumes you have a correlating date field called "Development Date" , "Production Date", "UAC Date" etc just to make the code clean but if the date fields aren't named like that already you can just alter the following to match the two with a case statement or a bunch of if's but hopefully it makes sense. Essentially x.title will give you the checked checkboxes display value.

var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:checked")

for (i = 0; i < x.length; i++) {
var y = x.title + " Date"
MakeFieldRequired(y);
}


Hope it helps
Brian
0 Likes
Absent Member.
Absent Member.

Will,

See how this works.

jQuery is a good thing to take a look at as it is just javascript on steroids. It was created to just make a lot of things you do with basic javascript much easier.

I would keep your original form action because that hides all the non-checked and then create another form action that runs on load after the first one that does the following. So let's assume you have a checkbox called Development and one called Production and one called UAC. The following code just assumes you have a correlating date field called "Development Date" , "Production Date", "UAC Date" etc just to make the code clean but if the date fields aren't named like that already you can just alter the following to match the two with a case statement or a bunch of if's but hopefully it makes sense. Essentially x.title will give you the checked checkboxes display value.

var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox:checked")

for (i = 0; i < x.length; i++) {
var y = x.title + " Date"
MakeFieldRequired(y);
}


Hope it helps
Brian
0 Likes
Fleet Admiral
Fleet Admiral

I try to use "out-of-the-box" SBM features whenever possible and go for the least amount of scripting. In my experience, scripts become maintenance nightmares. This is frustrating because, gosh darnit, I'm a coder and I want to write code. 🙂

Would this work? Add a form action like the one in the attachment below. The "Javascript" calls the "GetMultiListValues" SBM Javascript library function. This function returns an array of selected values. If that array contains an element with the text "Complete Development" then the Javascript returns true, and false otherwise. The remainder of the action should be pretty obvious.

The text of the Javascript line is:
GetMultiListValues("MULTI_REL").indexOf("Complete Development") >= 0 ;
0 Likes
Absent Member.
Absent Member.

Paul,

I agree, use out of the box functionality whenever possible. Although, I do not like using form Actions. They are cumbersome to build into every form and difficult to debug, especially if you have javascript in the mix.

My main app has 12 swim lanes of similar workflows just different install environments. To manage actions on all of those forms would be a nightmare. Easier to centralize the desired behavior within a javascript and add it to each form.

Brian,

Tried your idea with appending "Title" to date... Problem there is the title returned something like FJ304 instead of the expected string. The multirelational fields within the USR table store the values as ,1,3,4,5,12,15, related to the aux table. I think if you wanted to get the title you would have to cross reference the index values to the aux table and extract the title?

I used the Explorer debugger and found that the value that was readable was "Checked" returning true or false related to the index so I used that as the key into the problem....

Boy, javascript is picky on uppercase lowercase.... Took me a while to debug the incorrect "Makefieldoptional" should have been "MakeFieldOptional". Probably could have been nicer with a case statement, but it works.

Here's a few items out of the 14, did not want to bore you with all of the code. The code will turn on the date if the value checked and turn it off if its not checked:

AddLoadCallback(check_pending_List);
AddChangeCallback("PENDING_LOWER_ENVIRONMENTS", check_pending_List);
function check_pending_List() {
if (GetFieldWidgetByName) {
var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox(:checked)");
for (i = 0; i < x.length; i++)
{
var y = x.checked

if (i == 0 && y == true){MakeFieldRequired("Install Date Bcv1");}
else if (i == 0 && y == false){MakeFieldOptional("Install Date Bcv1");}

if (i == 1 && y == true){MakeFieldRequired("Install Date CERT");}
else if (i == 1 && y == false){MakeFieldOptional("Install Date CERT");}

} //End Loop
} // End first iff
} // End Function


Thanks for all of the help.

Regards,

Will
0 Likes
Absent Member.
Absent Member.

Will,

Sounds good if you got it working but here is my 2 cents on your code.

This line creates an array of ONLY the checked boxes

var x = $(GetFieldWidgetByName("PENDING_LOWER_ENVIRONMENTS")).find(":checkbox(:checked)");

So in your code y will always be true so your else if's won't ever hit.

Not sure what you were doing to have the title not show right but if you look at the source in the debugger the title attribute of the check box should be what is displayed on the form for the checkbox and the value attribute will be the 2,3,5,7 etc you mentioned.

BTW You will probably get bit by the javascript is case sensitive thing about 5 more times before it sinks in totally 🙂
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.