1

I have 2 lists, candidateList and emailList.

In ListA, and object has various fields such as candidate (lookup field) and a textBody. When viewing a ListA object I have added a button to email.

When selecting email, I want to direct the user to the emailList newItem form, with the candidate and the text from the bodyText and populate fields on the newItem form.

I believe that the best way to do this is via a query string, that when I click the email button, I pass the data to the newItem form.

Unfortunately I am not sure how to generate the query string to pass, and how to read that query string on the other form to populate.

From what I understand, on my email button press I need to pass the values in the url, like '/Lists/SentMails/NewFormInsert.aspx?candidate=@Candidate=1&bodyText=@BodyText' But those values are within a <xsl:value-of select="@Candidate"/>, so I need to somehow get the xsl value first as a string before I can pass it via the url?

Stumped at this point. :(

Any ideas or suggestions? Thanks!

(Using SharePoint Designer 2013)

0

Your use case can be divided into 2 parts.

1. Generate a URL which contains query strings:

As you have already placed a button on view form, then first get the url of email list new form which would be something like this http://yoursite/Lists/YourListName/NewForm.aspx?Source=value

you can tune it to http://yoursite/Lists/YourListName/NewForm.aspx?yourQuery=value&yourSecondQuery=value

Now if your button is html <button> then it will not have href and you will need redirect action via onclick event. So it is good to have a <a> tag. Which will allow you to place above URL in href.

2. On the destination form, retrieve values of query strings

Now on the email New Item form, you can have below JavaScript function.

var firstValue = '',
    secondValue = '';
function getQueryString () {
    try {
        var q = (function (a) {
            if (a == "") return {};
            var b = {};
            for (var i = 0; i < a.length; ++i) {
                var p = a[i].split('=');
                if (p.length != 2) continue;
                b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
            return b;
        })(window.location.search.substr(1).split('&'));

        //Here q is an array which will contain your query strings. So just use name and value can be fetched
        if (!isEmpty(q["queryStringName"])) {
            firstValue = q["queryStringName"];
        }
        if (!isEmpty(q["secondQueryStringName"])) {
            secondValue = q["secondQueryStringName"];
        }

    }
    catch (err) {
        alert("Error");
    }
}

function isEmpty (value) {
    return (value == null || value.length === 0);
}

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.