0

I have to customize the returning from saving and exiting (by canel) a list element. I know that is done by the source parameter in the url, but I did not understand how to set/edit it. If I take a look to my source code I see the following anchor:

<a id="idHomePageNewItem" class="ms-heroCommandLink" href="http://portal/projects/buchungsportal/_layouts/15/listform.aspx?PageType=8&amp;ListId=%7BA57192AA%2D80F8%2D4C4E%2D91DA%2D94131DCC2F47%7D&amp;RootFolder=&amp;BetriebId=1265" 
    data-viewctr="6" onclick="NewItem2(event, &quot;http://portal/projects/buchungsportal/_layouts/15/listform.aspx?PageType=8&amp;ListId=%7BA57192AA%2D80F8%2D4C4E%2D91DA%2D94131DCC2F47%7D&amp;RootFolder=&amp;BetriebId=1265&quot;); 
    return false;" target="_self" title="Ein neues Element zu dieser Liste oder Bibliothek hinzufügen.">
    <span class="ms-list-addnew-imgSpan16"><img id="idHomePageNewItem-img" 
        src="/_catalogs/theme/Themed/982A91AA/spcommon-B35BB0A9.themedpng?ctag=6" class="ms-list-addnew-img16">
    </span>
    <span>Neues Element</span>
</a>

When I click on my anchor the following url opens:

http://portal/projects/buchungsportal/Lists/Anfragen/NewForm.aspx?Source=http%3A%2F%2Fportal%2Fprojects%2Fbuchungsportal%2FLists%2FBetriebe%2FAllItems%2Easpx&RootFolder=&BetriebId=1265

Where does the source parameter come from? How can I customize it before sending the request to the server?

0

I guess you will have to create custom New/Edit forms for list items and will have to create custom buttons as below:

<td class="ms-toolbar" nowrap="nowrap">

<input type="button" value="Save" name="btnSave" onclick="javascript:{ddwrt:GenFireServerEvent('__commit;__redirect={put your url here} ')}" />

</td>

similarly for cancel button:

<input type="button" value="Cancel" name="btnCancel" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={/}')}" style="width: 101px" /> 
  • The custom forms are already written, but I can't adopt your solution, since I come to my form from different pages and i need to have different returning pages. – Emaborsa Jan 12 '15 at 8:28
  • @Emaborsa: then you can follow JS approach suggested in below blog. I haven't tried this but i think it should work adrianhenke.wordpress.com/2010/08/19/… – Amit Jan 12 '15 at 8:32
  • I already have read this post, but it does't explain how to it Via URL Parameter. – Emaborsa Jan 12 '15 at 8:48
0

I tried to do this multiple ways by modifying the Save button or the Redirect url but all of them cause other problems with the form, such as not validating fields.

I finally decided to check the Source parameter on open and if it's not right then set it and reload the page. Call this before document.ready for better performance.

function CheckSourceParameter(){
//GOAL: We always need to open a request with the right ?Source= parameter so we can launch the right page on save
//Check the param here and if it's not correct then recreate the url and reload the page


    var validSource = _spPageContextInfo.webAbsoluteUrl + '/SitePages/ThankYou.aspx';
    validSource = encodeURI(validSource);

    //get initial Source param, need encoded value
    var orgURL = document.location.toString();
    var orgSource = GetUrlKeyValue('Source', true, orgURL, true);

    //alert(orgSource + '\n\n' + validSource );

    //does the Source param match what we want; both values should be encoded before testing
    if(orgSource == validSource){
        //the Source param matches our desired url, nothing else to do here
        return; 
    };

    //the Source param doesn't match, need to update and reopen
    if(IsBlank(orgSource)){

        //just append the validSource to the url
        var newURL = orgURL + "?Source=" + validSource;

    }else{

        //need to replace the value in the url; both values must be decoded here
        var newURL = orgURL.replace(orgSource.toString(), validSource);
    };

    //alert(orgURL + '\n\n' + newURL);

    //reopen this form with the right Source param
    document.location = newURL;
};

IsBlank() is another custom function I wrote, but you just need to check if the value == '';

NOTE: You'll need to change your Cancel buttons or they'll open the ThankYou page too.

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.