JS in Item view: Why is document.thisItem.node.childNodes modified on lock/unlock?

While running a method OnFormPopulated, I reference the list document.thisItem.node.childNodes to get an overview of the properties of the current item.

This NodeList contains all elements on first load, however, when a lock/unlock action subsequently triggers the event, the list is missing several properties.

I.e. when the form loads the list contains all properties of the item but after locking/unlocking the item it will contain only some of them.

I haven't been able to find a common factor between the remaining or discarded properties.

Here is a simple test case:

1. Create a method TestPropsMissingOnLockUnlock:

console.log(document.thisItem.node.childNodes);

2: On an ItemType's form, attach it as a Form event with Event = OnFormPopulated

3: Open the item and check the logs.

My tests:

Test 1: Opening an unlocked item

Step 1.1: Opened the item
Logged result: NodeList(71) [..........]

Step 1.2: Locked the item
Logged result: NodeList(38) [..........]

Step 1.3: Unlocked the item
Logged result: NodeList(37) [..........]

Test 2: Opening a locked item

Step 2.1: Opened the item
Logged result: NodeList(71) [..........]

Step 2.2: Unlocked the item
Logged result: NodeList(37) [..........]

Step 2.3: Locked the item
Logged result: NodeList(38) [..........]

Why is this? And how can I ensure that I get all properties even when on subsequent OnFormPopulated triggers?

My current workaround is to check if we're still looking at the same item, and if so, store the nodeList to the window object and use that upon lock/unlock ...

Parents
  • Hi Silje Dahl

    This is because 

    When the item is loaded, nodes will have all the properties
    When the item is locked, nodes will have only the properties which is having values
    When the item is unlocked, nodes will have only the properties which is having values (Locked By ID is empty in this case). So, this will be always (locked nodes count - 1)

    Thank You

    Gopikrishnan R

Reply
  • Hi Silje Dahl

    This is because 

    When the item is loaded, nodes will have all the properties
    When the item is locked, nodes will have only the properties which is having values
    When the item is unlocked, nodes will have only the properties which is having values (Locked By ID is empty in this case). So, this will be always (locked nodes count - 1)

    Thank You

    Gopikrishnan R

Children