I am working on an on-premises sharepoint farm 2013. and i have added a Search Result web-part, which uses 2 display templates (Results Control Display Template + Item Display Template). now i am trying to find a way when users chose to edit and item inside the webpart, to be redirected back to the webpart page and not to the related list view.

now inside the Results Control Display Template, i am showing a popup when users click on ... beside the item title as follow:-

enter image description here

and the popup have the following code inside the display template:-

AddPostRenderCallback(ctx, function() {
    // Add a callout to each row
    SP.SOD.executeFunc("callout.js", "Callout", function () {
        var tableElement = document.getElementById(tableId);
        var targetElement = tableElement.getElementsByClassName('NotificationDiv');
        if (targetElement.length > 0) {
            for (var i = 0; i < targetElement.length; i++) {
                var elm = targetElement[i];
                var calloutOptions = new CalloutOptions();
                calloutOptions.ID = 'notificationcallout-' + i;
                calloutOptions.launchPoint = elm;
                calloutOptions.beakOrientation = 'leftRight';
                calloutOptions.content = String.format('<a href="{0}&PageType=4" onclick="javascript:tableLayoutDT.redirectToPropertiesUrl(this, \'{1}\');return false;" title="View properties">View properties</a><br /><a href="{0}&PageType=6" onclick="javascript:tableLayoutDT.redirectToPropertiesUrl(this, \'{1}\');return false;" title="Edit properties">Edit properties</a>', elm.getAttribute('rel'), elm.getAttribute('path'));
                calloutOptions.title = elm.getAttribute('ref');
                var displayedPopup = CalloutManager.createNew(calloutOptions);

now when users click on the View properties OR Edit properties links, the url will contain the Source parameter which equal to the wbepart page something as follow http://servername/sites/ITManagement/Shared%20Documents/Forms/EditForm.aspx?ID=34&Source=http://servername/sites/ITSGroup/SitePages/Documents.aspx&ContentTypeId=0x010100B38191C6F6C3A54689835468AA0B4AD100696338EF5849E842A88B42C674B975A3 where SitePages/Documents.aspx is the page containing the Search Result webpart, so users will be redirected back to the web-part page correctly after editing the item. now the problem i am facing is inside the Item Display Template when building item title link, where i am using the following code to build the item title link :-

var linkURL = $getItemValue(ctx, "Link URL");
String.format("<a href='{0}' class='ms-listlink' >{1}</a>", linkURL, property) 

but if i click on the item title link i will be redirected to the item display form, and if i chose to edit the item or click on close button, i will be redirected to the item's list view instead of being redirected to the web-part page, this is since the managed property Link URL does not contain the Source parameter. so can anyone adivce on this please? how i can force the item link to have the source parameter, and set this parameter to be equal to the web-part page?

Your Answer

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

Browse other questions tagged or ask your own question.