0

I have a SharePoint list "A" which should create a button whenever we add a new item to the list, and when we click on that button it should redirect to the list "B" newform.aspx with the list item values from the list "A".

list "B" will have couple of new columns other than coloumns in list "A". But it should only create the item in list"B" when user clicks on save button in list"B" newform.aspx.

0

I suggest you add a lookup column in the "List B" to lookup from the "List A", then create column "Link"(single line of text) in "List A", and use JSLink to build the Link.

1.Save the following code as a js file(LinkField.js) and upload it into the SiteAssets Document Library.

(function () {   
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        "Link": { "View": LinkField }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function LinkField(ctx) {
    var currentId = ctx.CurrentItem.ID;
    var title=ctx.CurrentItem.Title;
    return "<a href='/sites/team/Lists/ListB/NewForm.aspx?Title="+title+"&ListAItemId=" + currentId + "' target='_blank'>Link ListB</a>";
}

2.Edit the list view page and edit the list web part. Go to Miscellaneous -> JS Link.

3.Add the following URL into the JS Link textbox.

~site/SiteAssets/LinkField.js

enter image description here

4.To get the data from "List A" in the "List B" newform.aspx page, we can use the JS function below, example, get Title from "List A". Add the code into Script Editor web part in the newform.aspx page.

<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function () {
    //get Title value from list A
    var title=getUrlParameter("Title");
    //set title to Title field in list B
    $("input[title='Title Required Field']").val(title);
});
function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
</script>
  • Hi, Thank you so much for your help, is there a way that i can populate all the filed values from "list A" to "list B" newform.aspx using the ID of the list item in "list A" when user clicks on the button in "list A". because i want the values from "list A" which are going to populate must be disabled/non-editable fileds in "list B" newform.aspx. – renai Dec 18 '17 at 18:52
  • You can get the "List A" item in "List B" newform.aspx base on the ID of the list item in "List A" using jQuery Ajax and REST API. Or we can pass the value through the Link URL, like ?Field1=Value1&Field2=Value2. – LZ_MSFT Dec 19 '17 at 1:27
  • HI, Thanks again, one thing, is it possible to provide any syntax please. greatly appreciable. – renai Dec 20 '17 at 21:22
  • Hi samy, I change the reply, check if it helps you. – LZ_MSFT Dec 21 '17 at 2:46
  • Hi LZ-WX, Thank you for your response. Using REST API i'm able retrieve one column value from the "List A", but i couldn't bind the value in "List B" newform.aspx with the same column name. could you please help binding the retrieved values in "List B". any code would be helpful. Thanks. – renai Jan 13 '18 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.