Javascript API getParents() and NOTICE links


(Tim Davison) #1

Hi all 

 

Did a search but found nothing on this.  Function getParents() in the JS API does not seem to function as expected.

 

I am trying to get a list of all the NOTICE links for an asset (but would settle for simply all links) similar to what you see when you right-click an asset and look at the Linking screen from the backend.

 

I am using the following code:

var type_codes = [];
var link_types = [];
var link_values = [];
getParents (<my asset id>, 1, type_codes, link_types, link_values, 1, function(data) {
  // do something here
});

The above code returns any TYPE1 and TYPE2 links, but does not return any other links - I've confirmed on the Linking screen there are a number of NOTICE links (where the image is used in a page) and a NOTICE link for a Future Status.  But these do not come up in getParents in the JS API, even though the documentation clearly states NOTICE links should be returned.

 

I tried getChildren - which seems to return NOTICE links but this is going the wrong direction.

 

Is this a fault in getParents?  Or am I going about it the wrong way?  Is there another way I'm supposed to use to get NOTICE links?

 

Cheers


(Ashish Karelia) #2

Hi Tim,

Having a quick looks, it does look like the getParents() is no more returning the notice linked parent. This might probably be because of changes to the core functions of Matrix that the API queries. I will look into it and treat it as a bug.

Unfortunately I didn't any other function call that would help you achieve what you are after. ave it upto other forum user to see if they have worked around this issue before.

 

Ash


(Tim Davison) #3

Thanks Ash for the quick reply.  Out Matrix version is v4.12.4, by the way.

 

Cheers


(Tim Davison) #4

-- Update for those who may be looking for a workaround --

 

Use an asset listing with the following configuration:

  • Direct links only
  • Direction up the tree
  • Link types TYPE3 and NOTICE (depending on what you are looking for)
  • Dynamic parameter to replace the root node (I use 'rootid' as the parameter in the code below).
  • Set the asset types to list (this can be tricky - see below)

Then call in your JS code (where you would have called getParents) something like this:

$.get('./?a=<asset listing id>?rootid=' + <your asset you are looking at>, function(data) {
  // do something with data here
});

Depending on what you are trying to do will change what you return back in 'data'.  I only want to see if there is any notice link - I don't much care what it is.  So I just return some simple HTML that I then append into the DOM.  You could enhance it to return JSON, or other things, and nest further info.

 

One limitation seems to be that you can't get any more info immediately on the assets that are linked - not a problem if it's file types, but more complex types like standard pages, the NOTICE link will actually be to a container DIV, rather than the page itself.  You could add another asset listing, similarly to go up the tree and find an appropriate parent asset, or use getParents() and keep traversing up until you find where is_dependant=0.  (I didn't need this level of detail so I didn't implement any of this - just conjecturing).

 

But it does highlight the careful consideration needed to specify the asset types to return in the asset listing.  I listed Bodycopy Container (inherit) and Content Type (inherit) so far, which I will need to expand to more asset types as I figure out they are needed.