How Can I get Label of Check Box Variable Label by Catalog Client Script?

Sisozuki1
Kilo Contributor

Hi.

I created choice box fields like below.

Location (val_location)(Label)

  -placeA(val_place_a)(CheckBox)

  -placeB(val_place_b)(CheckBox)

  -placeC(val_place_c)(CheckBox)

 

I want to get Label of check box which selected.

For Example, I tried script like below when place B checked.

if(g_form.getValue("val_place_b")){

       g_form.addInfoMessage(g_form.getLabelOf("val_place_b"));

}

I expected that "placeB" message appear, but "Loctation"  appeared.

How can I get label of check box's?

1 ACCEPTED SOLUTION

DirkRedeker
Mega Sage

Hi

I had some time to investigate, but I found some solution for you:

Look at the Client Script below:

find_real_file.png

There is an array variable "nameMap" on the "g_form" object, which you can use to find the elements of the form (1) - see line 7. I print out the content of this object in line 11 to see the content.

In line 15, I compare the "realName" element of each Array element to find the "id" of the Control, which was calling this Client Script (2).

If it was found, I print out the Label (see line 16).

As you asked in your question, you want to search for the variable name(4), which I do in line 22.

When found, again I pipe out the label.

The next screenshot shows the output results, when I clicked the first option:

find_real_file.png

Here is the code for Copy&Paste:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   if(g_form.getValue("val_place_b")){
		var myFormObj = g_form.nameMap;   // gets access to the Objects on the current form
		var mySysID   = control.id;       // gets the Sys_ID of the Control for which the code runs

		// Print out the "form's nameMap"
		g_form.addInfoMessage(JSON.stringify(myFormObj, null, 4));
		// Search for the Control of this script
		var i = 0;
		for (i = 0; i < myFormObj.length; i++) {
			if (myFormObj[i].realName.toString() == mySysID.toString()) {
				g_form.addInfoMessage('The Label of the clicked element is = ' + myFormObj[i].label);
			}
		}

		// OR...
		for (i = 0; i < myFormObj.length; i++) {
			if (myFormObj[i].prettyName.toString() == 'val_place_b') {
				g_form.addInfoMessage('The Label (2) of the clicked element is = ' + myFormObj[i].label);
			}
		}
	}
}

 

Review this example in detail and let me know if that answers your question.

Please do not forget to mark my answer as correct and helpful to send me some donation on that 🙂

Enjoy & BR

Dirk

 

View solution in original post

5 REPLIES 5

old thread... unfortunately, nameMap isn't available on service portal.