cancel
Showing results for 
Search instead for 
Did you mean: 

setting article properties from webscript

schipmolder
Champ on-the-rise
Champ on-the-rise
Hi, I'm using a pretty much default deployment of 4.0.d with a web quick start site and I was wondering how i can get and set the value of a property using a javascript web script.

I've added a new property to the ws:article type of ws:readCount (d:int) and I'd like it to increment by one every time the article page gets loaded so I figured I should be able to read the ws:readCount on loading (in the page's web script js file), increment it by one and write it back to the article but I'm not having any luck whatsoever.
I know how to do it with a java backed web script but for this project I have to use the javascript web scripts.

Does anyone have an example of how to read/write the properties of an article?

Thanks
Skip
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
It appears that you have added your own custom property to Alfresco's out-of-the-box content model. You should not do that. Instead, extend the model with your own and add your own types, properties, aspects, etc., to your own namespace.

With that said, this code should do the trick:
var someDoc = search.findNode(args.nodeRef);
var counter = someDoc.properties['ws:readCount'];
counter += 1;
someDoc.properties['ws:readCount'] = counter;
someDoc.save();
More info:
JavaScript scripting API
JavaScript Cookbook
Intro to the Web Script Framework Tutorial

Jeff

schipmolder
Champ on-the-rise
Champ on-the-rise
Hi Jeff,

I understand your point about extending the model, but if the behaviours of the wqs module automatically changes the type of a new article to ws:article wouldn't that mean my custom properties would not be applied to those articles?
Or are you saying that I should extend the model, edit the source of the wqs module so it works with my custom:article objects and then re-build it myself?

Regarding the javascript webscript, I had something very similar before but the script doesn't seem to have a 'search' object so it throws a 'ReferenceError: "search" is not defined' exception.
Where would i be able to inject the searchservice into the bean (assuming it works the same as with a java backed webscript)?

Thanks again
Skip

schipmolder
Champ on-the-rise
Champ on-the-rise
Never mind, I figured it out.

Thanks for the suggestions
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.