Solved

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

Posted on 2014-12-16
3
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 32

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 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