cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Rule with JavaScritp

viperboys
Star Contributor
Star Contributor

Hi.. 

I am creating rules for a folder. I want a JavaScript function to be executed when creating a file. Where do I add this JavaScript function?

1 ACCEPTED ANSWER

Hi,

Please refer  this Thread , May be helpful to you.

View answer in original post

5 REPLIES 5

sanjaybandhniya
Elite Collaborator
Elite Collaborator

Hi,

You need create xxx.js with your function inside Repository->Data Dictionary->Scripts folder.

Create rule : Select Folder: Manage rule->Create New rule with following parameter.

Name : Provide rule name

Define rule : Select relevant option from dropdown.

Perform Action : Select execute script and choose your created xxx.js file.

Other Options: Select relevant option.

Hi @sanjaybandhniya 

Thank you very much.. This work very well! 

Hi @sanjaybandhniya 

I have followed all these steps that you told me. Apparently the script I select doesn't run. Please check.

My file is called GravityForm.js with this content

function traer(){
var user = "Luis";
var name ="Diaz";
alert("Nombre: " + user + " Apellido: " + name);

$.ajax({
type: "POST",
url: "http://localhost/alfresco/index.php/wp-json/gf/v2/workflow/webhooks/10/Fytn4QUNj9XWrzcvRzAPG79CB",
data:{Nombre:user, Apellido:name},
success: function(data)
{
alert ("Muy bien");
}
});


} // Cierra de la funcion TRAER
traer();

The rule is created this way

image

I add the GravityForm.js file in the /Repository/DataDictionary/Script directory

This does not run. I tested this code in a local installation and it works fine. Also try printing only one value like this console.log ("Test"); and it doesn't work either. I want it to run when a document is created.

Thank you

Hi,

You can not call ajax from rule script as it is server side script.