Hi, I am trying to figure out how to dynamically (via filtering) apply a specific item id to a display form.
I searched everywhere but I couldn't find anything on how to do it.
Can someone please help.
Hi, I am trying to figure out how to dynamically (via filtering) apply a specific item id to a display form.
I searched everywhere but I couldn't find anything on how to do it.
Can someone please help.
Hello @geolouca,
Do you mean you want to open the display form of the selected items dynamically?
You can set up redirection using the example from this article.
In case this is not what you are looking for, please provide more details about the use case so I could suggest something specific.
Hi @Margo,
We are using Sharepoint Online.
The information on the article about redirect and dynamically adding the ItemID on the URL occurs after a triggered event e.g. spSaved.
What is the requirement is when the page loads with a display form to be able to assign the ItemID to the Display Form when the Form renders.
We tried the simple adapted js without assigning the ItemId via a variable as below but it gives an error.
fd.spRendered(function(result) {
var listId = fd.spFormCtx.ListAttributes.Id
result.RedirectUrl =
"https://domain.sharepoint.com/sites/HumanResources/SitePages/My-Page.aspx?ItemID=18"
});
Hi @Margo,
I just noticed that the RedirectURL is only available under spSaved event.
So how can we dynamically assign the ItemId on Display Form load. The Display Form is on a page it self. It is not redirected following another event. As you can see from the redirect url we tried above is for employees to be able to see their personal details on their own page. Is this doable?
Thank you,
Hello @geolouca,
Ok, thank you for the details.
You can use window.location.href to redirect the user on form load.
The other question is how you determine the item contains current user details? Are you using Person or Group field?
Using PnPjs you can get the item ID of the corresponding item and build the correct URL.
Thanks @Margo,
I thought so as well. As we are new at this where do we place the window.locatin.href? Can we insert it in the form editor or should we use a snipped webpart on the SP page for this code.
Thank you,
Hello @geolouca,
If you want to redirect a user when he opens the form you can add window.locatin.href under spRendered event:
fd.spRendered(function(vue) {
window.locatin.href('URL');
});
And you need to add this code to the JavaScript editor in the form: