1

Using JSOM, I getting all the task details which are not started. Using CAML query i got all the column values including related item column from Task list

var relateditm = $(this).attr("ows_RelatedItems");
alert(relateditm);

The value i got is

[{"ItemId":6,"WebId":"da019015-45eb-cd62-83e2-dfb360620954","ListId":"25ca3434-de22-4ccf-8954-6564cc179ea6"}];

I want the Item ID alone. How can i retrieve the id from this?

I tried with the below code, but undefined error is coming

var relateditmid = relateditm[0].ItemId;

1 Answer 1

2

Base on your code, the value you get is a string not an object.

so the code : var relateditmid = relateditm[0].ItemId; will return the item ID after converting the string relateditm to Object using eval funtion.

var relateditmObj = eval(relateditm);
var relateditmid = relateditmObj[0].ItemId;
2
  • Thank you. It is working. If my question is useful. Vote UP :) Commented May 18, 2016 at 7:36
  • Not a big fan of eval. I would use JSON as the result you are receiving has JSON formatting: var relatedItem = JSON.parse(relateditm); var itemID = relatedItem[0].ItemId
    – Suleyman
    Commented May 18, 2016 at 7:41

Your Answer

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

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