Dynamically specifying which view to load

  • 2 December 2014
  • 1 reply
  • 0 views

Badge +4

I think this is related to another post http://community.k2.com/t5/K2-blackpearl/Loading-K2-Smart-Forms-Views-runtime-Dynamically/m-p/72900#M20917 but there didn't seem to be much detail about the solution.

 

I have a library with 17 content types (contracts) in it and I have been asked to create a SmartForm where the user can select the contract content type from a drop down control and then fill in the metadata, create a contract document and start a process.

 

I have seen that I can either create a single SmartObject via the SmartObject Service Tester or I can let SharePoint generate a SmartObject for each content type. That seemed okay so I created views from the SmartObjects. In the form I do not want to add every view and then try to manage the visibilty based on the dropdown if I don't have to.

 

What I would really like to do is lookup which view belongs to which Content type and then dynamically load the view as a subview perhaps. I would rather not have to have an If condition for every entry in th dropdown.

 

Is there a way of dynamically loading a view based on a value? Or is there an approach that you would recommend to achieve the requirement?

 

Thanks

 

Jeremy


1 reply

Userlevel 1
Badge +8

Hi Jem

 

One way to do this would be to place a View on the Form that contains a single Content Control. You can then dynamically change the URL property of the Content Control (using the "Set the Control Properties" rule) to different views depending on the user input (e.g. content type drop down).

 

You would need to maintain a list of content types and the associated view URL in a table and then create an associated SmartObject to display this data. You could use this SmartObject as the datasource for the content type dropdown and pass the selected URL value to the content type.

 

To help with deploying your solution to different environments (dev/test/prod) save the View URL value without the domain (e.g. /view/viewname) and use the environment library values to create the full URL to pass to the content control.

Reply