0

I have only had experience with using REST in a SPD workflow. How can I use jQuery with REST to have a user click a button and open up a mailto: link and have that link mail to the users returned from the REST call.

I have the query that I need, I just need to learn how to use it with jQuery.

1

First you need to add jQuery references to the Page as below

<script type="text/javascript" src="path/jquery-min.js"></script>

Now you can activate a REST call as follows

var url = RESTQUERY;

jQuery.ajax({
    url: url,
    type: "GET",    
    headers: { 
        "accept": "application/json;odata=verbose",
        "content-type":"application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
    },
    success: function(d) {
        var stringData = JSON.stringify(d);
        var jsonObject = JSON.parse(stringData);
        var results = jsonObject.d.results;
        for(i = 0; i < results.length;i++) {
            console.log(results[i]["Member"]["EMail"]) 
            //HERE YOU CAN FORM THE MAIL TO LINK
        }
    },
    error: function() {
        console.log('fail');
    }
});
  • I've almost got it returning what I need. In the console, it brings back the object, which is a person field. I need to grab the email from that field. I can get it in my REST query, but what do I put in the field name to expand on "Member"? (Member would be in place of Title in your example) – Jordan Dec 31 '14 at 15:22
  • Can you post the rest query, here.. Are you using $select then use the same as the field name. – Amal Hashim Dec 31 '14 at 15:25
  • This is my query <MySite>/_api/lists/getbytitle('My List')/items?$select=Member/EMail&$expand=Member – Jordan Dec 31 '14 at 15:26
  • Try Email as the field name.. Also when you put the query in browser you will get something like d:Email so whatever following d: should be used. – Amal Hashim Dec 31 '14 at 15:28
  • I get undefined if I use Email. In the console, it gets returned in the object of Member when I use that. Can I do more with that to grab it? – Jordan Dec 31 '14 at 15:33

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.