Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

808 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