cancel
Showing results for 
Search instead for 
Did you mean: 

create, edit, delete web scripts

tsgpartner_mui
Champ in-the-making
Champ in-the-making
I'm trying to develop some web scripts that would be able to create objects from a user's parameters (e.g. from a html form - users can enter in fields for title, description, etc) into the alfresco repository.


Once that is complete, I have to develop a web script that would be able to edit that object (e.g. change the title, description, etc.) and then, of course, a script to delete that object.


So far I created the desc doc xml and ftl html form for the 'create' webscript, but not sure how to code the javascript?? Also, I'm using the post method.  once i figure this out, the edit and delete shouldnt be too difficult to develop.


Can anyone provide some guidance in how I would do this or refer me to any similar examples of create, edit, delete??



Thanks
9 REPLIES 9

davidc
Star Contributor
Star Contributor
There are plenty of methods in the javascript api for creating, updating and deleting nodes in the repository.  Just use those.

http://wiki.alfresco.com/wiki/JavaScript_API

You can pass the item to edit/delete/use as a container via a URL argument (as a path, node id or whatever).

An example of uploading a file into a new node is at http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload

tsgpartner_mui
Champ in-the-making
Champ in-the-making
Thanks for the reply,

Yes I did see that upload example, but for my script I actually want to create the object without uploading a file.  Would it be possible to create an object only base on what users enter into the title and description fields, for example???

And if it is able, would I have to develop a GET and POST for the create web script??

davidc
Star Contributor
Star Contributor
Would it be possible to create an object only base on what users enter into the title and description fields, for example???

Yes - just use the create api.

And if it is able, would I have to develop a GET and POST for the create web script??

It depends on the URIs and methods you want to support.  The javascript & freemarker apis do not force a particular URI structure or HTTP method usage.

You can create objects in a single request (get or post or any other http method), but I would reserve get for repeatable, cachable requests only.

tsgpartner_mui
Champ in-the-making
Champ in-the-making
I see.

davidc
Star Contributor
Star Contributor
You're probably in a better position to debug this yourself.  You know what you want to achieve.

Again, take a look at the javascript wiki page - you'll find a createNode as well as a createFile method.

What error are you getting? Have you tried the Javascript debugger? Have you tried putting log statements in your code.

tsgpartner_mui
Champ in-the-making
Champ in-the-making
Heres the error:

The Web Script /alfresco/service/sample/create has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/sample/create.post.js': Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/sample/create.post.js': syntax error (AlfrescoScript#25)

Exception:   org.mozilla.javascript.EvaluatorException - syntax error (AlfrescoScript#25)



I dont have alot of background in javascript, but yea, going over the wiki page should help.

tsgpartner_mui
Champ in-the-making
Champ in-the-making
got it to work now.

tsgpartner_mui
Champ in-the-making
Champ in-the-making
for the edit script,

i want to find and display all the created objects from my create script, and then probably place an edit button next to each object (later, add a delete feature) and then once you click that, a user would be able to edit the title and description of that object and save.


I can prob figure out teh search part but was wondering if anyone could provide some advice on how I would handle the edit and save part for the javascript? is there any certain api, methods i should look at?

dooley
Champ in-the-making
Champ in-the-making
You can override any of the property values by just giving it a new value.  For example you have the property description set to the description that the user enters:


myFile.properties.description = description;

So, all you have to do is give it a new value:


myFile.properties.description = "your new description";

Saving is really easy. You just do the same thing out already did in your script.


myFile.save();