0

How do i get current logged in user phone number. I have a list with field name Requestor, Department and Phone Numver and using below code:

<script src="/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>  
<script src="/Scripts/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>  
<script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-0.7.2.min.js"></script>

<script language="javascript" type="text/javascript" src="/Scripts/sputility.min.js"></script>


<script type="text/javascript">  

$(document).ready(function() {  
    // get the title of current user  
    var UserName= $().SPServices.SPGetCurrentUser({  
    fieldName: "Title",  
   debug: false  
});  
// get department of current user
var userDepartment = $().SPServices.SPGetCurrentUser({
   fieldName: "Department"
   });
     // alert(userDepartment);

// get Phone of current user
var userPhone = $().SPServices.SPGetCurrentUser({
   fieldName: "Phone Number"
   });
      alert(userPhone);


//alert("Hi");
//populate the field ‘Requestor’ with the current account  
$('textarea[title="Requestor"]').val(UserName);  
$('input[title="Requestor"]').val(UserName);  

$('textarea[title="Department"]').val(userDepartment); 
$('input[title="Department"]').val(userDepartment); 


$('textarea[title="Phone Number"]').val(userPhone); 
$('input[title="Phone Number"]').val(userPhone);

});  

</script>

I am getting user name and department name but could not get phone number. Is there anything wrong in naming convention. Thanks

2 Answers 2

1

Checkout the documentation for SPServices.SPGetCurrentUser

The name of the field you want is Work Phone, not Phone Number.

As a side point, you should not be making three calls to SPServices to get the three field values. You can get all three values in a single call. The documentation has an example showing how to do this.

1
  • I have added: var userPhone = $().SPServices.SPGetCurrentUser({ fieldName: "WorkPhone" }); $('textarea[title="WorkPhone"]').val(userPhone); $('input[title="WorkPhone"]').val(userPhone); but this is again not working, list field name is WorkPhone as well
    – Brishal
    Jun 10, 2015 at 6:18
1

You can use WorkPhone instead of Phone Number.

Also check user profile properties and make sure its is mapped to the correct field.

var userPhone = $().SPServices.SPGetCurrentUser({
    fieldName: "WorkPhone"
});
1
  • I have added: var userPhone = $().SPServices.SPGetCurrentUser({ fieldName: "WorkPhone" }); $('textarea[title="WorkPhone"]').val(userPhone); $('input[title="WorkPhone"]').val(userPhone); but this is again not working, list field name is WorkPhone as well
    – Brishal
    Jun 10, 2015 at 6:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.