I need to call a form from other form (Change content type)

  • 2 March 2016
  • 8 replies
  • 17 views

Badge +4

Hi,

I have a list with 10 different content types.

The customer asked me to have a "Generic" form. They want to be able to call a specific form linked to one of the available content types.

I tried with the "Change Content Type" control, but it's not working on "New" forms. It's only showing up in "Edit" forms, and this is completely useless for me.

The customer wants to select the Content Type BEFORE doing the request. What's the point to do it after? After submit I already did the job and I have no need to change it!!

Please, can you explain me how can I meet the requirement?

I will really appreciate it!

Best regards


8 replies

Badge +11

Hi Ignasi,

how about using the standard capabilities of SharePoint? When creating a list item via the ribbon one has the possibility to choose from the available content types.

Capture.JPG

Isn't that enough for your customer? If you need a "generic" form, I would start trying different views on your form, which the user can then switch to by pressing a button e.g.. But stick to the (useful) OOTB SharePoint features is normally the best you can do.

Cheers

Philipp

Badge +4

Hi Philipp,

Many Thanks, but the OOB functionality is not a User Friendly solution. Most of the users don't know about SharePoint or how use the Ribbon options. They basically wants to do a simple click on a link, then have a "Generic Form" and then select the type of form they want.

Managing 10 views on the same form is like a nightmare. The complexity of each form is really high and they are adding more a more complexity each time. In fact that's the current solution, and it's a really nightmare to maintain. That's the reason we want to split the form, keeping the same user friendly interface (possibility to change the form type from a dropdown list).

It would be nice to have the ability to switch the views without JavaScript code, just like InfoPath does, but handle so many JavaScript to do this kinds of things is forcing us to think in simpler solutions.

Kind regards,

Badge +4

I'm not familiar with content types, but I'm assuming the URLs  are different for each new form for each content type?

you could build URLs on the generic form to the different content type forms.  If you go to the new form for a content type in the url is something like this:  ContentTypeId=0x012002001587ED4S5SD4CD144340B74C1

Add it to the url after:  /NewForm.aspx?

so:    WebURL/NewForm.aspx?ContentTypeId=0x012002001587ED4S5SD4CD144340B74C1

Badge +11

Parker Petty​ is completely right. The URL for the new item form is different for each content type as it includes the content type id. So you can do what he suggested. If you want to use a dropdown for this, you can just create this control on your form, provide the content type names as choices and use some javascript when this dropdown is changed to redirect your user to the respective URL.

Of course you will need to do this on every of your content types forms, but since you can copy/paste most of the stuff, even doing this for like 10 content types shouldn't take forever. For the javascript logic i would recommend not to code it separately in every form, but to create one single script and just link it in all of your forms.

Cheers

Philipp

Badge +4

Thank you guys!

Yes, this is the correct answer, I can do it without too much effort. Thanks for the idea!

But I'm still confusing about the strong limitation with "Change Content Type" Nintex Form control.

Nintex is meant to be easy to manage, not so tricky! It's really so difficult to add a parameter to let decide the author of the form if he want to show the control on the "New" view or not?

I'm having doubts about if its simpler to manage forms directly with aspx code than Nintex Forms and then a lot of JavaScript inside.

Thanks again for your help.

Best regards.

Badge +4

Hi Caitlin,

This is what I finally did (due to the limitations of this control OOB that I still not able to understand).

First, créate a dummy form, just with a dropdown control to let the user select the kind of request he want to perform.

186458_pastedImage_0.png

Then name your dropdown control with a specific name.

186459_pastedImage_1.png

Then add the next JavaScript code to your form.

Please, notice that in my case, all the requests (Content Types) are starting with a two-digit number, (01-..., 02-..., 03-...) so I'm taking this 2 digits to identificate the type of request, but you can do the same without any substring function and comparing directly the whole request name.

_spBodyOnLoadFunctionNames.push("startIt");

function startIt() {

   console.log("Page loaded");

   NWF$('#'+Reasonfortherequest).attr('onchange', 'redirect()'); //this is the event listener that calls the function redirect() each time someone change the value of the dropdown list

}

function redirect() {
   var reason=NWF$('#'+Reasonfortherequest).val().substring(0,2); //In my case, all the Content Types starts with a two-digit number, so I'm taking this 2 digits, but you can do the same without the substring and comparing the whole request name.
   var commonURLStart="/Lists/GenericRequest/NewForm.aspx?Source=https%3A%2F%2FYOUR_SP_SITEURL_HERE%2FLists%2FYOUR_LIST_NAMEt%2FAllItems%2Easpx&ContentTypeId=";
   var commonURLEnd="&RootFolder=%2Fsites%2Fworkflows%2Fgeneric%2FLists%2FGenericRequest";
   var CT_GUID_99 ="0x0100072FAB56042023449DB9236F64FD36B6070035600F47A039B34984B203BB7C95AD7B";
   var CT_GUID_01 ="0x0100072FAB56042023449DB9236F64FD36B60100BABAB3F8C9877A418A956F70A8536E2E";
   var CT_GUID_02 ="0x0100072FAB56042023449DB9236F64FD36B60200FE08D049C4E2E645A94D3386008373D3";
   var CT_GUID_03 ="0x0100072FAB56042023449DB9236F64FD36B60300E3246A761474B34E90B0D4677BFA3A63";
   var CT_GUID_04 ="0x0100072FAB56042023449DB9236F64FD36B6040054D34EB00A9E8B499E8755B4FDCFD47A";
   var CT_GUID_05 ="0x0100072FAB56042023449DB9236F64FD36B605001B45F89754D3224F867B09A0BD4FC472";
   var CT_GUID_06 ="0x0100072FAB56042023449DB9236F64FD36B60600B28D4A93D9C9674EBBC7038B01877E4B";
   var CT_GUID_09 ="0x0100072FAB56042023449DB9236F64FD36B6080020ECEDABF594AE45946C818318B9D71C";
  
   var redirectionURL ="";
   switch (reason) {
       case "01":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_01 + commonURLEnd);
       break;
       case "02":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_02 + commonURLEnd);
       break;
       case "03":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_03 + commonURLEnd);
       break;
       case "04":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_04 + commonURLEnd);
       break;
       case "05":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_05 + commonURLEnd);
       break;
       case "06":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_06 + commonURLEnd);
       break;
       case "09":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_09 + commonURLEnd);
       break;

       case "99":
            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_99 + commonURLEnd);
       break;
       default:
                 console.log(reason);
       }
}

I hope this helps!

Nintex Support​ Are you looking what kind of JavaScrip you are forcing us to add into forms? It's so difficult to let the "Change Content Type" control work also on "New" ones?

Best regards.

Badge +4

Hi Caitlin,

Yes, you need to replace the GUID of each Content Type. This code was only a sample, but each Content Type has its own GUID and you need to replace it by yours.

As I said, my Content Types are all of them starting with two-digit numbers, and that's the reason I'm getting these numbers to operate with them on the code, in your case, if your content type is more like a single string (let's say "bill" and "PurchaseOrder"), then you need to replace the code with something like this:

var redirectionURL ="";

   switch (reason) {

       case "Bill":

            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_01 + commonURLEnd);

       break;

       case "PurchaseOrder":

....

CT_GUID_01, CT_GUID_02, CT_GUID_03 are only variables name to store the GUID of each CT, you can rename it as you want. Please, ensure you have only the code for YOUR Content Types, in my sample I put height of them due I had 8 CT, but maybe you only have 4, then delete the rest of lines you don't need.

To figure out the GUID of your content Types, please, go to your list containing these CT and then go to list settings, on the CT section, you will see all the names of them.

186478_pastedImage_0.png

You need to click one by one and take the Content Type GUID from the URL in your browser.

For instance, in my case, I have something like this:

var redirectionURL ="";

   switch (reason) {

       case "01":

            window.location.assign( _spPageContextInfo.webAbsoluteUrl + commonURLStart + CT_GUID_01 + commonURLEnd);

       break;

       case "02":

.../_layouts/15/ManageContentType.aspx?List=%7B6F777EFA%2DFF0F%2D49F9%2DB661%2D49DF12F7F311%7D&ctype=0x0100072FAB56042023449DB9236F64FD36B60100BABAB3F8C9877A418A956F70A8536E2E

Then the GUID for this CT is

0x0100072FAB56042023449DB9236F64FD36B60100BABAB3F8C9877A418A956F70A8536E2E

I hope this helps.

Best regards,

Badge +4

Hi Catlin,

Please, try it replacing also the name of your list instead my list "GenericRequest" was on my side, not on yours:

var commonURLStart="/Lists/BrokerCommpanyProfile/NewForm.aspx?Source=..."

Sorry for not specify this also on the code, some times i forgot the most obvious things...

Best regards.

Reply