jeudi 12 mars 2015

Sharepoint2013 ctx and Js : Retrieve the value of a field from a list



I'm a totally beginner and totally stuck to a point in my Sharepoint project.


What i would like to achieve:



  • part 1 : retrieve the current user's Department's name

  • part 2 : retrieve the department's website's url from a custom list using ctx, and jquery. (I'm totally new to REST, so please no REST answer)


Structure of the custom List:



  • name = "O Services"

  • field's name i would like to retrieve from that list : "URLSitesServices"

  • field's name of the department : "Service" So, for example, in O Services, i have an item called (field Name) "Information Service", whose URLSitesServices is "http://mysite/service".


So, on site homepage, if user's department is Information Service, i would like to go in O Services, search for the Service called "Information Service" and retrieve its URLSitesServices


What i've already done:


part 1 is complete, i'm able to retrieve the current user's department's name.


i'm stuck in part 2 : i don't know how to ask for O Services, i don't know how to retrieve the different items, nor their different fields...


Here is my code so far :



SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() {
getMyProfileProperties(
function(profileProperties){
var fullProperties = profileProperties.get_userProfileProperties();
var myDepartment = fullProperties["Department"];
if (myDepartment){
var ctx2 = new SP.ClientContext();
var targetList = ctx2.get_web().get_lists().getByTitle('Services Osiris');
console.log(myDepartment);
}else{
console.log("nothing");
}
},
function(sender,args){
console.log('Error occurred while getting user profile properties:' + args.get_message());
}
);
});
});


My targetList does just return a array, no useful values. i don't know how to retrieve the items, i saw get_items() etc.. but it does not work (i'm sure i'm making a lot of mistakes too)


Coul you please give me some hints, some clues to begin with, please? Thanks a lot in advance!








0 commentaires:

Enregistrer un commentaire