Execute Script Action - Calling REST Service and Populating Fields
Original Post by PJamhour (Imported from Ardevia Forum)
I am currently calling a REST web service (on button click) to return data from the SharePoint User Profile Service. The call works fine and I am able to parse the JSON response.
However, I would like to extract some elements from the JSON response and set them as form field values. But attempting to set the values through the Execute Script action does not seem to be doing anything.
Here is the code that I am using in my Execute Script Action.
Code:
jQuery.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "https:///_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|"+[[Requestor.Email]]+"'",
data: "",
dataType:"json",
success: function(resp){
alert(resp.UserProfileProperties[10].Value);
[[]] = resp.UserProfileProperties[10].Value;
},
error: function(e){
alert(e.Message);
}
});
The only thing that I can think of is setting the value of another field to this JSON response, and then using the set form field value action to process that data, per field I want to populate.
-
Original Post by Liliia (Imported from Ardevia Forum)
Hello,
Please try this code:
Code:
jQuery.ajax({ type: "GET", contentType: "application/json; charset=utf-8", url: "https:///_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|"+[[Requestor.Email]]+"'", data: "", dataType:"json", success: function(resp){ alert(resp.UserProfileProperties[10].Value); var inputController = jQuery('span.ms-formbody[fieldname=""]').closest('.ard-formfield').data('Controller'); var val = resp.UserProfileProperties[10].Value; inputController.InstanseData.SetValue(val); }, error: function(e){ alert(e.Message); } });and let me know if it is helpful.
0 -
Original Post by PJamhour (Imported from Ardevia Forum)
Hi Liliia,
That is exactly what I was after.
Thank you very much.0 -
Original Post by Liliia (Imported from Ardevia Forum)
You are always welcome! Please feel free to contact us in case of further difficulties.
0
Please sign in to leave a comment.
Comments
3 comments