Content Types & Related items

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Hubbaroo
Posts: 60
Joined: Sat Sep 21, 2013

30 Sep 2013

We are clear on how to create a related item using the information contained in this site. We would like to understand how to create a related item in a list with multiple content types. The current method only creates the default content type. Can you explain how to, based on a field in the parent form, create the related item using other than the default content type.


Thank you.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

04 Oct 2013

Hello,

You can override the standard function NewItem2 and inject the specific content type id into the new item link by placing the following code into JS-editor of Forms Designer:

Code: Select all

var contentTypeId = '0x010600818BDDA1EEF42845841F01B81D898F04';

if (typeof (window.NewItem2) === "function") {
  var NewItem2Orig = window.NewItem2;
  window.NewItem2 = function (evt, url) {
    var ch = url.indexOf('?') >= 0 ? '&' : '?';
    url += ch + 'ContentTypeId=' + contentTypeId;
    return NewItem2Orig(evt, url);
  }
}
You have to set contentTypeId variable in the required content type id. To get it go to the list settings, select the specific content type and find ctype parameter in the query string. It contains the ID of the selected content type.

User avatar
Adam Reyes
Posts: 35
Joined: Tue Mar 04, 2014

11 Aug 2017

I realize this is an old post but this doesn't seem to be working in my version of Forms Designer. I'm using Forms Designer v3.1.3

The javascript code you provided doesn't seem to affect the new item button and continues to open the default content type which is "Document".

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

14 Aug 2017

Hello, Adam!
The code still works. Follow these steps to make sure everything works as intended.

1) Make sure you created a New Form for the Content Type. Content Type for the Form can be selected in Forms Designer in the top right corner:
ContentTypeDesigner.png
ContentTypeDesigner.png (2.33 KiB) Viewed 2980 times
2) You need to make sure you use correct ID for the Content Type you are trying to open Form for. Add Content Type field to the Form and use this command in browser's console to get the correct ID:

Code: Select all

fd.field('ContentType').control()._el().find('select').val();
[/code]
ContentTypeField.png
ContentTypeField.png (3.65 KiB) Viewed 2980 times
ContentTypeConsole.png
ContentTypeConsole.png (2.72 KiB) Viewed 2980 times
3) Insert this code inside Parent Form(one with Related Items) and check browser's console to see if it works or not:

Code: Select all

var contentTypeId = '0x010700F7059CD2918A9648AAD4EC65A40178CC';

if (typeof (window.NewItem2) === "function") {
  console.log("NewItem2 updates");
  var NewItem2Orig = window.NewItem2;
  window.NewItem2 = function (evt, url) {
    var ch = url.indexOf('?') >= 0 ? '&' : '?';
    url += ch + 'ContentTypeId=' + contentTypeId;
    console.log("NewItem2 opens");
    return NewItem2Orig(evt, url);
  }
}
Cheers

Office365Guy
Posts: 21
Joined: Sun Feb 24, 2019

13 May 2019

We have 5 related item controls on the form. Please clarify how we insure the correct one creates the correct content type. In other words, where in the script is the related control part.

Thank you!

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

16 May 2019

Hi!

Unfortunately, you can't do that for a concrete one. "NewItem2" is a global JS function - you can't override it for a certain Related Items control - only globally.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests