0

I am using Sharepoint 2013. i just wrote basic javascript code for our users get properties. it's not exactly what I can handle.

<script>
$(function(){
    var date1 = moment().format("MM/DD/YYYY");
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Kisiye Ozel Duyuru')/Items?$select=Title,ID,Duyuru_x0020_Atanan/Title,Duyuru_x0020_Aciklama&$expand=Duyuru_x0020_Atanan/Id";
           $.ajax({
              url: requestUri,
              type: "GET",
              headers: {
                  "accept":"application/json; odata=verbose"
              },
              success: onSuccess,
              error: onError
});


  function onSuccess(data) {
    if(data.d.results.length > 0){
        var objItems = data.d.results;
        var atanan = objItems[1].Duyuru_x0020_Atanan.Title;
        var baslik = objItems[1].Title;
        var aciklama = objItems[1].Duyuru_x0020_Aciklama;
        console.log(data.d.results);
        console.log(GetUserinfo());
        Bildirim(atanan,baslik,aciklama);
    }
   }
    function onError(error) {
        alert('Bildirimde bir hata var !');
   }
  });
  function Bildirim (atanan, baslik, aciklama){
  swal({
   title: '<strong>Sayın '+atanan+'</u></strong>',
  html:
    '<b>'+baslik+'</b>, ' +
    ''+aciklama+'' +
    '',
  imageUrl: 'http://intranet.uma.com.tr/SiteAssets/Duyuru.png',
  showCloseButton: false,
  showCancelButton: false,
  focusConfirm: false,
  confirmButtonText:
    '<i class="fa fa-thumbs-up animated wow bounceInLeft"></i> Tamam!',
  confirmButtonAriaLabel: 'Tamam!',
  cancelButtonText:
    '<i class="fa fa-thumbs-down"></i>',
  cancelButtonAriaLabel: 'Thumbs down',
});
  }
let GetUserinfo = function  () {
    // Wait until SP.JS has loaded before calling getWebUserData 
    ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
}

var context = null; 
var web = null; 
var currentUser = null;
var userGroups = null;
var displayGroups = null;

function getWebUserData() {

    context = new SP.ClientContext.get_current();   // Get the current user 
    web = context.get_web();                        // Get the current web    
    currentUser = web.get_currentUser();            // Get the current user 
    context.load(currentUser);                      // Load the current user 

    context.executeQueryAsync(kaka, onFailureMethod);
}

let kaka = function () {

    /*/alert('User name:' + currentUser.get_title() + '\n Login Name:' + currentUser.get_loginName());/*/
    var myJSON = JSON.stringify(currentUser);
    var userTitle =currentUser.get_title();
    return userTitle;


}

function onFailureMethod(sender, args) {

    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

}


</script>

Here my code. i tried console.log(GetUserinfo) it return undefined. but i write 'alert(GetUserinfo())' in my kaka function its correctly work. I just need get value or property. Where am i wrong ?

3
  • GetUserinfo is async function that means it waits untill some script is loaded AND THEN executes the function. So instead console.log(userInfo) inside getWebUserData() function Commented Dec 21, 2018 at 11:25
  • or even better inside kaka function since getWebUserData() is also async function Commented Dec 21, 2018 at 11:25
  • this function should return a value i cant return value with my function. Commented Dec 21, 2018 at 11:31

1 Answer 1

1

Here my Solution, i am using SPservice.js Library and add properties my arraylist and return list;

 function UserProperties() {
        myGroups = new Array();
        var Name = $().SPServices.SPGetCurrentUser({
        fieldName: ["Title"],
        debug: false
        });
        myGroups.push(Name);
        var Email = $().SPServices.SPGetCurrentUser({
        fieldName: ["EMail"],
        debug: false
        });
        myGroups.push(Email);
        var Picture = $().SPServices.SPGetCurrentUser({
        fieldName: ["Picture"],
        debug: false
        });
        myGroups.push(Picture);
        console.log(myGroups);
        return myGroups;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.