Getting an item property in onChangedCell from a recently created relationship vs existing relationship
- 7 years ago
Hi Ken,
I tried running this in an 11.0 SP15 instance I have installed locally, and I was able to get the existing related item using your sample above. I think the issue you may be running into is that the querySelector needs special formatting for IDs that begin with a number. You can see the sample below for how you might handle these kinds of IDs.
var my_item;
var firstChar = relatedID.substring(0, 1);
if (isNaN(parseInt(firstChar)))
{
my_item = parent.item.querySelector("#" + relatedID)
}
else
{
// If the ID begins with a number, we need to escape that character
firstChar = "\\3" + firstChar;
var restOfId = relatedID.substring(1);
my_item = parent.item.querySelector("#" + firstChar + " " + restOfId);
}var my_property = aras.getItemProperty(my_item, "item_number");
alert(my_property);Chris
Christopher Gillis
Aras Labs Software Engineer
- 7 years ago
Thanks Chris! I'm using 11sp12. I did some digging and it turns out all my test cases happened to begin with a non-number character. So this didn't fix the problem I was running into. However, I created some more items till I got a number as the first character and the code you provided helped with that case. Thank you for your help resolving another problem before it even happened! [emoticon:c4563cd7d5574777a71c318021cbbcc8]
Trying to find out more about when/why the method fails, I dug more into the debugger and found that I'm not always getting an item element back from parent.item.querySelector(), sometimes I'm just getting the relatedID back:
When it works:
my_item = item#9D10DBF4F748479981FD06B4CC4C31B6 {namespaceURI: null, prefix: null, localName: "Item", tagName: "Item", id: "9D10DBF4F748479981FD06B4CC4C31B6", …}When it doesn't work:
my_item = related_id#9D10DBF4F748479981FD06B4CC4C31B6 {namespaceURI: null, prefix: null, localName: "related_id", tagName: "related_id", id: "9D10DBF4F748479981FD06B4CC4C31B6", …}I realized I needed to define a better selector to get the correct element from the dom since querySelector() just returns the first match. I updated the code Chris provided to include updates to the CSS selector:
var my_item; var firstChar = relatedID.substring(0, 1); if (isNaN(parseInt(firstChar))){ my_item = parent.item.querySelector("Item[id=" + relatedID + "]"); } else { // If the ID begins with a number, we need to escape that character firstChar = "\\3" + firstChar; var restOfId = relatedID.substring(1); my_item = parent.item.querySelector("Item[id=" + firstChar + " " + restOfId + "]"); } var my_property = aras.getItemProperty(my_item, "item_number"); alert(my_property);
This seems to have resolved the issue I was having and the issue Chris preemptively helped with.
Thanks again Chris!