Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a listview setup on my page which shows orders from an orderlist. Works great. Now I want to add a column which displays an icon. When the user clicks this icon, the NewForm.aspx page from another list should popup. This other list also contains an ordernumber column, so I would like this column to be prefilled by the ordernumber of the line on which the user clicked the item.

I already know how to pass along the ordernumber to my javascript method, and I know how to get the NewForm.aspx page to popup in a modal popup using the modal framework. But now for the last challenge: how am I going to transfer the ordernumber from my javascript method into the correct textbox on the NewForm.aspx page? As far as I know there's no ootb way of passing in default values via querystring or something like that, right?

So I see two possible options:

  1. A query string parameter and some code on the NewForm.aspx to get this value and set the textbox.
  2. Getting the displayed page in my javascript method after the popup is displayed and setting the value throug there.

I have no clue on what the best / correct approach would be, or maybe I'm missing a better option? So I'd like your point of view on this.

share|improve this question
    
I have a close issue with your problem, I want to fill my newform.aspx with the current url where the user call the form. Did you find a solution? –  user5379 Oct 25 '11 at 9:43
add comment

4 Answers 4

up vote 1 down vote accepted

I think you're on the right track; either of your two options would work. In the past, I've used a JavaScript function to open a modal window with the form, and pass a query string to the form. You can then use some simple JavaScript to detect the query string and populate the form; I tend to prefer that approach since it doesn't require customizing the form in SharePoint Designer.

share|improve this answer
add comment

I had the same task. I found that NewForm.aspx handles automatically query strings which surprised me. The query strings must use internal names. And there is no need for custom code. So to pre-fill Title in the NewForm.aspx (even if you see "Titel" or "Tittel" or something else), just add ?Title=Hurray, like

SP.UI.ModalDialog.ShowPopupDialog("/Lists/Tasks/NewForm.aspx?Title=Fantastiskt");
share|improve this answer
add comment

I know this is an old answer, but I thought I'd chip in:

Most people use the query string approach. The SPServices plug in is really useful here (http://spservices.codeplex.com/), or you can write your own javascript within the form to get querystring parameters. I normally bundle this in to my own method:

function getQueryParameters() {
    var qObj = {};
    var urlSearch = window.location.search;
    if (urlSearch.length > 0) {
        var qPart = urlSearch.substring(1).split('&');
        $.each(qPart, function(i, item) {
            var splitAgain = item.split('=');
            qObj[splitAgain[0].toLowerCase()] = splitAgain[1];
        });
    }
    return qObj;
}

You can then access the values:

var qString = getQueryParameters();
var myValue = qString["myValue"];

I would like to point out that Anatoly Mironov's answer is not correct: The only field that you can pass without additional code in the query string is the 'Title' field. I have tried all kinds of permutations with other fields, using the internal column name and the display name to no avail.

share|improve this answer
    
Great advice here! I've used SPServices and jQuery to pop up a custom modal form that has only the necessary fields for my use case scenario (and not the ribbon and other sharepoint boilerplate styling). Then, you create the record with SPServices and gracefully close the form. It is a bit of extra work, but the UX experience increase can be dramatic. –  tyshock Jan 17 at 15:57
add comment

I would recommend the querystring approach, it is a standard and clean way to pass data.

Benefits:

  • you can point to your newform from various locations
  • it'll work in both modal mode and standalone
  • it'll work across sites and domains

Another option would be to use cookies. I sometimes use them in longer processes.

share|improve this answer
    
Cookies is a bit overdone. Do you perhaps have a good example of how to do this using querystring? I'd also need a way to deploy that adapted NewForm.aspx file with my solution. –  Jasper Oct 20 '11 at 9:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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