Solved

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

Posted on 2014-12-16
3
413 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 with 3rd Party Video hosting 2 36
SharePoint 2013 Searchbox Branding 11 45
SharePoint Online/365 with SAP API 2 68
SharePoint Online Security 5 49
Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

864 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

21 Experts available now in Live!

Get 1:1 Help Now