Content Types & Related items
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.
Thank you.
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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:
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.
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);
}
}
- Adam Reyes
- Posts: 35
- Joined: Tue Mar 04, 2014
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".
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".
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 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: 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]
3) Insert this code inside Parent Form(one with Related Items) and check browser's console to see if it works or not:
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: 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: 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
-
- Posts: 21
- Joined: Sun Feb 24, 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!
Thank you!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 14 guests