How do you set the redirect asset of a Redirect Page using the Javascript API?


(J Stephen) #1

I'm trying to use the JavaScript API to create Redirect Page assets.


I can successfully create a Redirect Page using createAsset, but I'm having trouble setting the asset to redirect to. I had assumed it would be an attribute that you could set using setAttribute() but that appears not to be the case. Then I noticed that RedirectPages have a child link with a NOTICE link type to the redirect asset, so I tried createLink() to create a link to the asset I want to redirect to, but that doesn't seem to work either.



Does anyone know how to do this?



Thank you!


(J Stephen) #2

Looks like I've figured it out. In order to create a link of type NOTICE, you have to pass the value 8 to createLink() in the link_type argument.

    createLink(12345, 12348, 8, 'redirect_asset')


Where the parent_id is the Redirect Page and the child_id is the redirect asset, link_type is 8 and link_value is 'redirect_asset'.

Run this and then when you go to the details page for your Redirect Page, you will see the child_id set as the redirect asset.

I found out that 8 is the value for link type NOTICE by looking in core/include/init.inc

    define('SQ_LINK_TYPE_1', 1); 
    define('SQ_LINK_TYPE_2', 2); 
    define('SQ_LINK_TYPE_3', 4); 
    define('SQ_LINK_NOTICE', 8); 

(Anthony Barnes) #3

Glad you were able to find a way around that. There is also a gotcha with the setStatus function in that you need to provide the number of the status. These numbers and their corresponding status are also stored in the php code (eg, "Safe Edit" is 64), but I tend to cheat a little when I want to find out which status number to use for a particular status change and inspect the source code of the status select on the details screen of an asset.


(Nic Hubbard) #4

[quote]
Glad you were able to find a way around that. There is also a gotcha with the setStatus function in that you need to provide the number of the status. These numbers and their corresponding status are also stored in the php code (eg, "Safe Edit" is 64), but I tend to cheat a little when I want to find out which status number to use for a particular status change and inspect the source code of the status select on the details screen of an asset.

[/quote]



I think these need to be added as a js comment in the .js file for the JS File Asset. :slight_smile:


(Anthony Barnes) #5

That sounds like a practical idea, I'll put it forward to the development team.


(J Stephen) #6

Hi guys. Thanks very much for your replies.


I think commenting the allowed values for some of the arguments is a very good idea - as a developer I'd definitely find it useful and time-saving.