Solved

Sharepoint 2013 - New related list item, of a specific Content Type, auto linked

Posted on 2014-12-16
3
411 Views
Last Modified: 2014-12-19
We have a Sharepoint 2013 site, with lists for People, and Applications.

When we click on a person record to 'view' their person details (the default People list Display Form) - we have added a list web part to show the 'related' items from the Applications list.

The Applications list has several content types representing the different types of applications - each of which has different columns that are required.

We are currently able to click a hyperlink to open a new 'item' from the Applications list and have it pass through the related_person_id.  What we are missing is how to construct the hyperlink to open a specific content type when clicked.

Here is the current script we are using to identify the person id, and then find a hyperlink, and replace it with one that appends the related_person_id field value:

<a href="javascript:NewItem2(event,&#39;http://sp01/sites/eligibility/Lists/Eligibility_Applications/NewForm.aspx;);">New App</a>
<!--    Name: DisplayRelatedPeople.js -->
   <script src="/sites/eligibility/DevDocs/jquery-1.11.1.min.js" type="text/javascript"></script>
   <script type="text/javascript">

jQuery(document).ready(function($) {

    //get the ID for the Issue from the Query String
    var issueID = getParameterByName("ID");
    //find the element with the "New Application" link.
    //note that if you have more than one list on your page, this just finds the first one
    var anchorElement = $("a:contains('New App')");
    $(anchorElement).attr("href","javascript:NewItem2(event,'http://sp01/sites/eligibility/Lists/Eligibility_Applications/NewForm.aspx?Related_Person_ID="  + issueID + "');");    
    });

// The following function should really be put into a utility library
// with all of your commonly called functions
//
// no, I didn't write this function from scratch, I found it at
// http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

</script>
0
Comment
Question by:adjen13198
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Jamie McAllister MVP earned 500 total points
ID: 40504500
I'd create items of specific content type like the script below. Check out the querystring params and see if it helps you;

 
<p><input id="clickMe" onclick="createPop();" type="button" value="Create a new Invoice Document"/> <br/><br/></p>
<p>&#160;</p>
<p><a class="ms-rteFontSize-3" href="/Invoices">View all existing Invoice Documents</a><script class="ms-rteFontSize-3" type="text/javascript">


function CloseCallback(dialogResult, returnValue)
{
    if(dialogResult == SP.UI.DialogResult.OK)
    {
        SP.UI.Notify.addNotification('New Invoice Created');
    }
 
    if(dialogResult == SP.UI.DialogResult.cancel)
    {
        SP.UI.Notify.addNotification('Invoice Not Created');
    }
}

function createPop()
{
 
var options = SP.UI.$create_DialogOptions();
 
options.title = "Create New Invoice Document";
options.width = 610;
options.height = 650;
options.allowMaximize = false;
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
options.url = "http://MySite/Invoices/_layouts/NewDocSet.aspx?List=8ef9649e%2D51ba%2D45d7%2D8fe1%2De4a5aa008923&RootFolder=%2FInvoices&ContentTypeId=0x0120D621000125FC11AC384B44AA3C566411D4DF9900D4A3C0817901ED46AA845204C857C07C&IsDlg=1";
 
 SP.UI.ModalDialog.showModalDialog(options);
}</script> </p>

Open in new window

0
 

Author Comment

by:adjen13198
ID: 40504946
Thanks - I will try the code and advise!!
0
 

Author Comment

by:adjen13198
ID: 40509633
Thanks very much for the link.  I was able to get it to work!!

Much appreciated

Adam
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SharePoint and OneDrive 1 63
Change Master on a View Sharepoint 2016 6 44
Onedrive for business 3 29
Sharepoint server slow 4 26
I recently came across an issue with a MOSS 2007 deployment where access into some sub-sites were denied, even for the MOSS farm administrators. A bit of background to the setup of this MOSS farm; this was a three server setup, consisting of a fr…
There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now