Creating Rule with JavaScritp

cancel
Showing results for 
Search instead for 
Did you mean: 
viperboys
Active Member II

Creating Rule with JavaScritp

Jump to solution

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 Solution

Accepted Solutions
sanjaybandhniya
Intermediate

Re: Creating Rule with JavaScritp

Jump to solution

Hi,

Please refer  this Thread , May be helpful to you.

View solution in original post

5 Replies
sanjaybandhniya
Intermediate

Re: Creating Rule with JavaScritp

Jump to solution

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.

 

viperboys
Active Member II

Re: Creating Rule with JavaScritp

Jump to solution

Hi @sanjaybandhniya 

Thank you very much.. This work very well! 

viperboys
Active Member II

Re: Creating Rule with JavaScritp

Jump to solution

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

Alfresco » Reglas de carpeta - Google Chrome 2020-05-13 12.08.28.png

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

 

sanjaybandhniya
Intermediate

Re: Creating Rule with JavaScritp

Jump to solution

Hi,

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

sanjaybandhniya
Intermediate

Re: Creating Rule with JavaScritp

Jump to solution

Hi,

Please refer  this Thread , May be helpful to you.