cancel
Showing results for 
Search instead for 
Did you mean: 

Troubles with creating Association

lista
Star Contributor
Star Contributor
Hi everyone,

I'm not sure what I'm doing wrong, so I need your help.
I'm getting the following error message:

Failed to create new space due to error: Failed to execute script 'workspace://SpacesStore/f65b8966-615e-4607-8808-fd2a41499855': TypeError: Cannot find function createAssociation.
for the following piece of code:

var sourceNode =  document.nodeRef;


sourceNode.createAssociation(nodes[i].nodeRef, "mq:containsPhysicalEntities");

Any help will be appreciated.

Cheers.
Lista.
3 REPLIES 3

lista
Star Contributor
Star Contributor
It's as if I don't have a hold of node (and I think I do).
Am I missing something? Do I need to search for a node in another way in order for this to work?

mikeh
Star Contributor
Star Contributor
sourceNode should really be called sourceNodeRef as it won't actually be a node.

Try
document.createAssociation(nodes[i].nodeRef, "mq:containsPhysicalEntities");
Thanks,
Mike

lista
Star Contributor
Star Contributor
Hi MikeH,

thank you for your answer.

I was making a stupid mistake, I realize that now.
I was using document.nodeRef and did not realize it's a simple string, and could not use it as a reference.

This code will work:

var sourceNode = search.findNode(document.nodeRef);
var targetNode = search.findNode(nodes[i].nodeRef);


targetNode.createAssociation(sourceNode, "mq:containsPhysicalEntities");