cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Adding javascript validation using DataUtilities on create wizard

VINO
12-Amethyst

Adding javascript validation using DataUtilities on create wizard

Hi all,

I have a requirement of driver and dependent attributes which is based on selection of one value from combobox other attribute values should get populated. I'm referring to this solution https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS64401.

So I have created a data utilities class which is mapped to my driver attribute. And from that I can able to

call my javascript function which I have added in jsp page.

And that onchange validation also working fine. But my javascript function is not changing the value of other attribute.

Here is my javascript function.

<script type="text/javascript">

function customChangefunction(){

var target = window.document.getElementsByName("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

switch (strUser) {

case 'one':

target.options.length = 0;

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

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

target.options.length = 0;

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

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

target.options.length = 0;

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

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = document.createElement("OPTION");

opt.value = value;

opt.text = text;

ddl.options.add(opt);

opt.appendChild(text);

document.getElementById(ddl).appendChild(opt);

}

</script>

Can some tell me this is the correct way of doing it. And why this js function not working? From onchange I'm getting

the selected value.

And I have one more doubt if my dependent attribute is already having some values will this override and populate what we give here?

Please suggest me some solution.

ACCEPTED SOLUTION

Accepted Solutions
KD
12-Amethyst
12-Amethyst
(To:VINO)

Hi Vino,

First you make the driver attribute a Enumerated Value list then thriugh javascript you first remove the value and again populate the value with the required one.

function customChangefunction(){

var target = window.document.getElementsById("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

while (target.options.length) {

target.remove(0);

}

switch (strUser) {

case 'one':

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

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

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

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

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

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = new Option(value,text);

dd1.options.add(opt);

}

Added one document for similar type of job.

Regards,

Kaushik

View solution in original post

11 REPLIES 11
KD
12-Amethyst
12-Amethyst
(To:VINO)

Hi Vino,

First you make the driver attribute a Enumerated Value list then thriugh javascript you first remove the value and again populate the value with the required one.

function customChangefunction(){

var target = window.document.getElementsById("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

while (target.options.length) {

target.remove(0);

}

switch (strUser) {

case 'one':

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

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

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

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

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

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = new Option(value,text);

dd1.options.add(opt);

}

Added one document for similar type of job.

Regards,

Kaushik

VINO
12-Amethyst
(To:KD)

Thanks a lot kaushik for your solution and document.

If possible please share the source code mentioned in document related to this.

Anyway I will try your suggestion and let you know.

KD
12-Amethyst
12-Amethyst
(To:VINO)

Source codes are already inside the word document.

In case of any problem let me know I will upload them again .

VINO
12-Amethyst
(To:KD)

Oh okay. Actually I'm using open office because of which contents are not showing properly.

Thanks again

vmhala
10-Marble
(To:KD)

Hi Kaushik,

I have followed all the steps in the document which you have provided, but im not at all getting the list itself... please see the pic which is given below.asdf.jpg

vmhala
10-Marble
(To:vmhala)

Hi kaushik,

we are getting the dropdown for country not for the states, could you help us out regarding this?

vuchekar
10-Marble
(To:VINO)

Hi Vino / Kaushik,

Similar type of requirement we have.

Our requirement is like below, Country, State, City are attributes on Problem Report page. when we select Country respective States from that country should display in States drop down and when we select the Appropriate State from drop down, City's belongs to that state should display in next city's drop down,

we are referring Kaushik's approach and able to populate Country's Drop down so far, but we are facing issues when we are trying to populate States drop down.

Please help us to solve this issue.

Regards,

Vivek

Ritesh
3-Newcomer
(To:vuchekar)

Hello  Granite ,

 

I am also getting country dropdown properly but facing issue with State dropdown.Have you resolved this issue.

 

@Kaushik,

 

Please suggest .

Since Windchill 11.1 you are able to configure this in the type and attribute manager (called: Cascading Attributes)

You don't need to do it with java script anymore.

I was trying to achieve cascading behavior between attribute in Windchill 11.0.

 

I am able to achieve it.

 

Steps:

1)Write DataUtility for cascading  attributes.

2)write javascript function (within onscope jsp page).

3)Call that Java script function from datautility (for onchange event).

4)Make Ajax call within Javascript function.

 

Hope this will help someone working on similar requirements.

Do let me know if anyone stuck somewhere while writing code.

 

Thanks.

tspain
8-Gravel
(To:Ritesh)

Hi Ritesh, I have a similiar use case but with a twist.  I am using CS138327 to generate an External Enumerated Value List for Attribute1 (I am querying on all Contexts in the Windchill system).  I am able to export the Context List to a property file so that the pull down always has the full list of Contexts that currently exist in the system.       

 

Note:  Because I am using the External Enumerated Value List for Attribute1, the Cascading Attributes functionality in 11.1 will not work. 

From PTC Documentation:  To be used in a cascading attribute rule, an attribute must have a string data type, and a single, enabled enumerated value list constraint directly backed by a global enumeration.

 

Now I want to take the Context selected for Attribute1, and use that to produce the list of Roles that are contained in the Context.  I want to put this list of Roles in a pulldown for Attribute2.

 

I am able to write all of the backend code that I need to get the Contexts and Roles.  What I am lacking is the front end experience to make this work.  Would you be able to share the source code/locations required for you to get your examples to work?

 

Thanks,

Troy

Announcements


Top Tags