cancel
Showing results for 
Search instead for 
Did you mean: 

change dynamically simpletype reference of context variable

Former Member
0 Kudos

I had created 2 simple types(A and B), and add the fist in a context X.

In the context tab, i select then the context element X will be the type of simple type A.

How can, via code, in wdDoInit(), i change my wdContext.currentContextElement.X to be map to simple type B?

Thanks in advanced!

Bruno

Accepted Solutions (0)

Answers (1)

Answers (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Bruno,

Yes you can do this. Please use the following code. In the code below I am adding the simple types from starting. That means, first I will add the first simple type (A) then later I will add the other second simple type (B) to the same context attribute. Also please note that before doing this you need to do more step.

1) Create 2 dummy attributes in the context node and bind them with the 2 simple types. For e.g.: AttributeA binded with simple type A, and attributeB binded with simple type B. These attributes will act as the data source for your new attribute.

2) Now use the following code for that attribute which you are using in the view.


// Modifiable simple value set for the main attribute. For your case you can relate it to X attribute. I am assuming that attribute is directly under context node.
	  IModifiableSimpleValueSet attrSimpleType = wdContext.getNodeInfo().getAttribute("MAIN_ATTRIBUTE_NAME").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();
	  
	  // Modifiable simple value set of 2 dummy attributes. AttributeA and AttributeB which I am assuming are directly under context node
	  IModifiableSimpleValueSet source1 = wdContext.getNodeInfo().getAttribute("AttributeA").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();
	  IModifiableSimpleValueSet source2 = wdContext.getNodeInfo().getAttribute("AttributeB").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

	  
	  // Using the first set to fill the simple value set
	  if(source1!=null && source1.size()>0){
		int size1 = source1.size();
		 for (int i = 0; i < size1; i++) {
			attrSimpleType.put(source1.getKey(i), source1.getText(i));
		}
	  }
	  
	  // Clearing the set to add a new set
	  attrSimpleType.clear();
	  
	  
	  // Now using the second set for filling the simple value set
	  if(source2!=null && source2.size()>0){
		  int size2 = source1.size();
			 for (int i = 0; i < size2; i++) {
				attrSimpleType.put(source2.getKey(i), source2.getText(i));
			} 
	  }

I hope this solves your issue. Please revert back in case you need any further information regarding this.

Thanks and Regards,

Pravesh