Base on your code, the value you get is a string not an objectstring not an object.
so the code :
var relateditmid = relateditm[0].ItemId;var relateditmid = relateditm[0].ItemId;
will return the item ID after converting the string relateditmrelateditm to Object using eval funtion.
var relateditmObj = eval(relateditm); var relateditmid = relateditmObj[0].ItemId;
var relateditmObj = eval(relateditm);
var relateditmid = relateditmObj[0].ItemId;