1

After successful execution of context.executeQueryAsync(res, rej); I have weird stuff in res(response) callback with weird object content as { $9_0: something, $bla_bla: anotherSomething}. But I can clearly see pretty response of ProcessQuery response.

Code I have:

let context = new window.SP.ClientContext();            
window.Microsoft.Office.Server.ReputationModel.Reputation.setRating(
    context, 
    utils.extractGuid(item), 
    item.Id, 
    val);
context.executeQueryAsync(res, rej);

I don't want to use .load() Item to retrieve it's new property, but wanna extract it from response.

Is there way to serialize or retrieve proper things from response?

Example: .setRating()'s ProcessQuery returns new avarageRating as 5 enter image description here but callback of Promise returns strange looking object enter image description here

Thanks!

4
  • 1
    That "strange looking object" is just SharePoints internal javascript variable notation :-) Commented May 17, 2017 at 13:14
  • Thanks, I see. And how to retrieve actually result of query? Should I use some constructor on it? Commented May 17, 2017 at 13:15
  • You have to make sure to load the element with context.load(), here is a MSDN article: msdn.microsoft.com/de-de/library/office/… Commented May 17, 2017 at 13:17
  • So there is no way to extract raw response, without storing item that I've changed etc in variable? Commented May 17, 2017 at 13:18

2 Answers 2

3

Those are the private properties you should not mess with (Microsoft can change the encoded names for any next version)

Remember this is all (and fairly good) OOP Programming, that means you can't tinker with Properties from out side the Object

Check the .prototype chain (that __proto__ in your screenshot) for available Methods (better yet, check the documentation... but just checking the pc is often faster)

In the given example

The get_id , get_displayName , get_hasUniqueRoleAssignments are Methods (specific to this type of Object) you can use to access data values

The above is an Item as example


In general with JSOM you have to use Methods; you can't get values from the Object yourself.

5
  • I don't have item as I didn't use .load(item) and simply called Microsoft.Office.Server.ReputationModel.Reputation.setRating(context, utils.extractGuid(item), item.Id, val); context.executeQueryAsync(res, rej). That's all. I don't need any information about item, I just wanna retrieve response Commented May 17, 2017 at 13:33
  • You get a JSOM Object from the Server.. what that is depends on what you asked for. Objects have Methods that can give you the data ... OOP Commented May 17, 2017 at 13:35
  • Pity, but this Object don't have method .showResponseAsItIs() Commented May 17, 2017 at 13:37
  • So the proper way is actually do something like item.get_item('avarageRating') -> Microsoft.setRating() -> context.load(item) -> executeQueryAsync() and in callback .get_item('avarageRating) will be already updated? Commented May 17, 2017 at 13:40
  • 1
    I know the feeling, the Object of my love here doesn't have a "itsBeerOClockInAmsterdamGetMeOne" method... Is your question wrong? You want to update a Rating (and haven't checked the blogs)? Handling a response can only be done after a succesful query, If you do the query syntax wrong, then there is no point in trying to understand a response (which in you case then could very well be an Error reply) Commented May 17, 2017 at 13:43
0

Pity, but SharePoint pros do not allow to extract response as is, and only way to achieve expected result is to retrieve adjusted property by my own:

    let context = new SP.ClientContext();   
    let item = context.get_web().get_lists().getById(guid).getItemById(itemId);
    Microsoft.Office.Server.ReputationModel.Reputation.setRating(
        context, 
        guid, 
        itemId, 
        val);
    await new Promise((res, rej) => context.executeQueryAsync(res, rej));
    context.load(item);
    await new Promise((res, rej) => context.executeQueryAsync(res, rej));
    return item.get_item('AverageRating');

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.