Client-side Custom Action Scripting

You can define Custom Actions to appear in the actions menu of an opened object or the marked objects of a list within the client. You can configure for which users (roles) and which object types the action is available. Actions can have a localized title and description. The action script is executed within the browser Javascript environment. In combination with yuuvis® RAD agent, external applications can be called, including parameters. 

Set up Custom Actions in yuuvis® RAD management-studio via Main menu > Custom actions.

Include a script for the action and an optional script that checks whether the action is available based on the object data.

Scripts are executed in the browser. Use the browser debugging function to fix any errors.

Script

Use the scope object to make the properties of the marked objects and API functions available to the script.

Sample Script: Showing all objects of the marked context folder in the result list

apiAccess to the plug-in API to offer services for user information, notifier, and http call. For more information, refer to the Client-side Form Scripting documentation.
action

Contains information about the executed custom action, for example:

{
	action:	{
		title: "My action title",
		description: "My action description",
		id: "99468A41B55544B7A98F1457A84F8EAE",
		isexecutable: "callback(scope.objects.length==1);",
		modified:"2018-03-23T14:13:38Z",
		modifier:"johnson",
		requiredrole:"AllUserRole",
		script:"var agent = scope.api.agent;
				var notifier = scope.api.util.notifier;
				agent.getAvailability().then( function(state) {
					if( state == 'eo.agent.availability.connected' ){ 
						agent.executeAction("eo.agent.action.external", {executable: "baretail.exe"});
						notifier.success('Runs...'); 
					} else { 
						notifier.error('Without agent I do nothing ...'); 
					}
				});",
 types:["contract","idpicture"]

	}
}
objects

Array containing the object information of opened or marked objects.

var objects = scope.objects[0];             // take first object of array

const query = {
	filters: {contextfolderid: {o: "eq", v1: objects.id}}  // see Search Service API
};

const superQueryParams = `result?query=${encodeURIComponent(JSON.stringify(query))}`

window.open(superQueryParams,'_blank');  // opens result state with query in new browser tab

Sample Script: Calling external application with parameters

// define some local variables as shortcuts
var agent = scope.api.agent;           
var notifier = scope.api.util.notifier;
// var value = scope.values[0];              // with version 3.3 use this syntax, deprecated with version 4.0
var value = scope.objects[0];
agent.getAvailability().then( function(state) {         // this promise is evaluated as follows:
  if( state == 'eo.agent.availability.connected' ) {
    // If the yuuvis RAD agent is installed and running on the workstation where the client is used, an external program can be started as follows:
    agent.executeAction("eo.agent.action.external",
      {
        executable: "exampleapp.exe",     // 'exampleapp.exe' must be in the folder named 'agent externals' in the same level as the yuuvis RAD agent installation directory.
        args: [ 'ID='+value.id, 'Title='+value.title, 'Type='+value.type.name, 'Version='+value.version ]  // these parameters are passed through
        // Index data fields can be accessed with value.data.<technical field name>
      }
    );
  } else {
    // if the agent is not available
    notifier.error('Without yuuvis® RAD agent, nothing will happen. Please activate the agent.'); 
  }
});

Sample Script: Offering a Custom Action in versions state and calling external application to compare index data of the two marked versions

Script
var agent = scope.api.agent;
var notifier = scope.api.util.notifier;
var objects = scope.objects;
var payload = [JSON.stringify([{id: objects[0].id, version: objects[0].version}, {id: objects[1].id, version: objects[1].version}])];

agent.executeAction('eo.agent.action.external', {executable: 'compareversions.exe', args: payload});
Decision script
var objects = scope.objects;

callback((objects && objects.length === 2) && (objects[0].id === objects[1].id));

Sample Script: Send e-mail with custom subject and body

As of version 6.10 you can use this e-mail feature:

// define some local variables as shortcuts
var agent = scope.api.agent;          
var notifier = scope.api.util.notifier;
var value = scope.objects;
agent.getAvailability().then( function(state) {         // this promise is evaluated as follows:
  if( state == 'eo.agent.availability.connected' ) {
    // If yuuvis RAD agent is installed and running on the workstation where the client is used, an external program can be started as follows:
    var attachments = value.map(o => { return { id: o.id, title: o.title, rendition: "", version:null, type: o.typeName } });
          // these parameters are used by the agent to fetch the attachments from the backend
    agent.executeAction(agent.action.MAIL,
      {
		// message is not mandatory
		// as of version 6.16: to, cc, bcc accept strings, comma-separated strings and a string Array;
      	message: {
    		from: "mail@mail.to",
			to: "mail2@mail.to",
			cc: ["mail3@mail.to", "mail4@mail.to"],
			bcc: "mail5@mail.to, mail6@mail.to",
		  	text: "some fancy text",        // as e-mail body text
	      	subject: "some fancy subject"   // as e-mail subject
      	},
        attachments: attachments        // attach all document files of the corresponding objects to the e-mail
      }
    );
  } else {
    // if the agent is not available
    notifier.error('Without yuuvis® RAD agent, nothing will happen. Please activate the agent.');
  }
})


Sample Script: Delete rendition for renewal

In rare cases, a rendition can be corrupt. A rest call can help to delete the corrupt rendition. Afterwards, a new rendition is created when a user wants to see it. 

Decision script
var data = scope.objects[0];
scope.api.http.del('/dms/' + data.content.id + '/content/rendition').then(()=> {
   scope.api.events.trigger( 'eo.dms.object.updated', data);
});

Sample Script: Get the text of a document file

The following example shows you how to get the pure text of the document file of the currently focused object if you want to analyse this:

Example Getting the text of a document file
var object = scope.objects[0]; //The object whose file contents should be read
scope.api.http.get('/dms/' + object.id + '/content', '', { responseType: 'text' }).then(
    function (result) {
        scope.api.util.notifier.info('Success');
        //place your code for the file contents here
        //result contains the file's data as string   
    },
    function (error) {
        scope.api.util.notifier.error(error + '', 'Error');
    }
);


Decision Script

The 'scope' object makes properties of marked objects available to the decision script.

The 'callback' function expects 'true' or 'false' as a call-up parameter. When 'true,' the action is offered in the actions menu of the client.

Example

The custom action should be offered only if exactly one object has been marked:

  • callback(scope.objects.length==1); 

In the versions view, the custom action should be offered only if the marked object is the active version:

  • callback(scope.objects[0].isActiveVersion);

External Applications

External applications called up using the script require yuuvis® RAD agent and must be included in the 'agent externals' directory. This directory must be in the same level as the yuuvis® RAD agent installation directory.