Link to home
Start Free TrialLog in
Avatar of adjen13198
adjen13198

asked on

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

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>
ASKER CERTIFIED SOLUTION
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adjen13198
adjen13198

ASKER

Thanks - I will try the code and advise!!
Thanks very much for the link.  I was able to get it to work!!

Much appreciated

Adam