Solved

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

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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