Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:38:53+00:00 2026-06-13T12:38:53+00:00

I am working with the Sharepoint Client Object Model using javascript and looking to

  • 0

I am working with the Sharepoint Client Object Model using javascript and looking to make as much of my code as reusable as possible.

Examples of using the COM usually looks like this with a call and then a success delegate function to output the results.

function loadProfile()
{
    var context = SP.ClientContext.get_current();         
    var web = context.get_web();         
    var userInfoList = web.get_siteUserInfoList();
    camlQuery = new SP.CamlQuery();         
    camlQuery.set_viewXml('');         
    this.listItems = userInfoList.getItems(camlQuery);         
    context.load(listItems);         
    context.executeQueryAsync(Function.createDelegate(this, this.onProfileSuccessMethod), Function.createDelegate(this, this.onFail));     

}
function onProfileSuccessMethod(sender, args) 
{
    var item = listItems.itemAt(0);
    var first_name = item.get_item('FirstName');
    var last_name = item.get_item('LastName');
    alert(first_name + " " + last_name);
}

function onFail(sender, args)
{
  alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
}

What I am trying to achieve is being able return the values after instantiating an object but given that it is asynchronous I am not sure how this is possible, would I need to “listen” for the call to complete before values are returned.

Would it be something like this? Or can you not have a delegate function internal to the function it creates it from. Apologies for my limited understanding!

var profile = new loadProfile("testid");
alert(profile.onProfileSuccessMethod());


function loadProfile (id) 
{
    this.user_id = id;
    var context = SP.ClientContext.get_current();         
    var web = context.get_web();         
    var userInfoList = web.get_siteUserInfoList();
    camlQuery = new SP.CamlQuery();         
    camlQuery.set_viewXml('');         
    this.listItems = userInfoList.getItems(camlQuery);         
    context.load(listItems);         
    context.executeQueryAsync(Function.createDelegate(this, this.onProfileSuccessMethod), Function.createDelegate(this, this.onFail));    
   this.onProfileSuccessMethod = function() 
{
    var item = listItems.itemAt(0);
    this.first_name = item.get_item('FirstName');
    this.last_name = item.get_item('LastName');
        return this.first_name


    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:38:54+00:00Added an answer on June 13, 2026 at 12:38 pm

    If it is asynchronous, it is impossible to return values from it. You need to use a callback pattern.

    function secondStep(data){
        console.log(data)
    }
    
    var profile = new loadProfile("testid", secondStep);
    

    and

    function loadProfile (id, callback) 
        ...
        this.onProfileSuccessMethod = function(){
            callback({});
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am working on a Silverlight integration with SharePoint. I use the Client Object Model
I am currently developing a service using the SharePoint 2010 Client Object Model to
I have an html question. I'm using sharepoint - working on Sharepoint Designer. I'm
I'm working on some SharePoint web parts and I'm trying to make them as
Working on a small game using an HTML5 canvas, and javascript. And it's working
I'm working on Add to Calendar feature from my Sharepoint webpart (created using VS2010).
I have some working code that I have been using on a test O365
I'm working with Sharepoint at the moment and to say it's code structure/layout is
I was looking for help last week to get a simple javascript code made
I'm working with a client to plan the topology for a public facing SharePoint

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.