Question

I edited my display form for a cusotm list using sharepoint designer, and i added the following link, which reference the create form inside another list:-

<a href='/sites/****/Lists/Details/NewForm.aspx?Source=&RootFolder=' > + Add New Details</a>

but i am not sure how i can get the URL for the current display form (which contain the item ID /Lists/Device/DispForm.aspx?ID=15)and add it to the Source= parameter inside the above link? so the above link will be as follow <a href='/sites/****/Lists/Details/NewForm.aspx?Source=/sites/****/Lists/Device/DispForm.aspx?ID=15&RootFolder=' > + Add New Details</a> so when users add the item inside the external create form, they will be redirected to the display form again?

Thanks

Was it helpful?

Solution

Not sure if you need a way to do it in aspx directly since you didnt mention, but you could do it in jQuery quite easily.

First add a class to your link ->

<a href='/sites/****/Lists/Details/NewForm.aspx?Source=' class='addDetails'> + Add New Details</a>

Then you retrieve href using jQuery and you save it in a var ->

var initialHref = $(".addDetails").attr('href');

After that you can take the current url location like this ->

var currentLocation = window.location.href

And finally you put them together

$(".addDetails").attr('href', initialHref + currentLocation);

It will give you the entire link appended to Source (starting with https), but if you dont want that you could probably split the var (using string.split vanilla js) https://www.w3schools.com/jsref/jsref_split.asp

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top