Scripts

In UpexPro system the user can not only use the existing possibilities, but also create his own tools for operating. It can be realized by creating scripts it Java Script. Maintenance of the scripts is performed with tools of the reference guide “Files”, they can be started by dragging from reference guide to the system objects. To make the file be accepted as a script it’s necessary to install the connection “Script”.

Of course its content should be exactly the script. Below you can find the description of operating with scripts.

User script

User script should be realized as a procedure with name “userfunc”, it doesn’t return anything and takes an input variable “reqData”. The variable “reqData” is an object with array “reqArr” which includes the system objects consisting of two fields “id” and “type”, where “id” is an unique identifier of item in type objects, “type” – system object type. Except of specified array the “reqData” includes the property “event”, which initially has a null value. Afterwards the value will be set by user when request transmission to the server with the purpose to select the operation the server should perform with transmitted system objects.  Also “reqData” and each element of array “reqArr” have a field with name “error”, which contains the error code for query execution by the server. The error codes you can find in attachment to this manual. Below you can see an example:

This user script will show the message in browser containing the object “reqData” for system object (objects) for which this user script was applied. Below you can see the example of the message displayed by such script:

The object “reqData” is intended to provide to the user script the information about an object or objects to which it should be applied. Also the further transfer is possible of this object to the server to perform any operations with system objects.

All necessary tests for conformance / nonconformance of the input data to the user script algorithm should be performed by user directly in scrip performing.

Request to server

Request to the server should be performed by function “apiDoRequest”. The function has one input parameter “reqData”, its format is similar to the data format transferring to the user script by the system as considered above. This feature allows transferring the data from system to server without problems and making the necessary changes simultaneously. The function returns the modified variable “reqData”, the array “reqArr” inside this variable contains not only the fields “id” and “type”, but also the other fields typical for this type of system object.

Read request for system object data:

To request the system for an object fields it’s necessary to call the function “apiDoRequest”, transferring to it a variable “reqData” as a parameter, with field “event” equal to “get_data”.  Below you can see an example of variable “reqData” to request the object fields of the system object like “Items” with ID code «21».

The array “reqArr” can contain the unlimited numbers of system objects of different type, for which it’s necessary to provide the information. Below you can see a request example for several system objects.

The field “error” in sent data doesn’t play any role and is necessary to be processed only upon receipt of reply from server (server replies in the same format, but add to “reqArr” array content, except of fields “id” and “type”, also the other fields typical for this system object).  Below you can see the example of server reply to the above mentioned request.

Procedure of the user script performing the JSON line output as a browser message looks like this:

Read request for system object data can be performed for the following system objects types:

  • Nomenclature item – data of the field “type”:“nomenclature”;
  • Collection – data of the field “type”:“collection”;
  • File – data of the field “type”:“file”;
  • Parameter – data of the field “type”:“parameter”;
  • Component – data of the field “type”:“component”;

Error indication

There is a system of error codes if the server request is performed with some errors or is not performed completely.

If the request was not performed completely (for example the wrong value was indicated in the field “event”) the server will return the message of the following format:

The data of the field “event” in such message will be kept from the request; the field “reqArr” is missing.

If the request was performed for several system objects and some of the requests failed (for example because of missing read rights), in this case the server will return the following message:

Objects of the system

The system contains the following types of objects:

  • Nomenclature item;
  • Collection;
  • File;
  • Parameter;
  • Component;

The server returns the system objects in format of JSON line with the following fields structure:

Nomenclature item:

  • id – unique item identifier in objects of its type;
  • type – type of the object (“nomenclature”);
  • name – designation of the item;
  • notation – name of the item;
  • created_date – date of item creation;
  • change_date – date of item change

Collection:

  • id – unique item identifier in objects of its type;
  • type – type of the object (“collection”);
  • name – designation of the item;
  • notation – name of the item;
  • link_type – link type of the item;
  • status – status of the item;
  • start_date – date of start;
  • start_time – time of start;
  • end_date – date of end;
  • end_time – time of end;
  • created_date – date of item creation;
  • change_date – date of item change;

File:

  • id – unique item identifier in objects of its type;
  • type – type of the object (“file”);
  • name – name of the file;
  • file_type – type of the file;
  • link_type – link type of the item;
  • comment – comment for the item;
  • size – size of the file in bytes;
  • created_date – date of item creation;
  • change_date – date of item change;

Parameter:

  • id – unique item identifier in objects of its type;
  • type – type of the object (parameter);
  • name – designation of the item;
  • notation – name of the item;
  • parameter_type – type of the parameter;
  • created_date – date of item creation;
  • change_date – date of item change;

Component:

  • id – unique item identifier in objects of its type;
  • type – type of the object (“component”);
  • nomenclature_id – identifier of the nomenclature item used for component creation;
  • parent_obj_id – identifier of the collection containing this component;
  • parent_id – identifier of parent object “component”-type in component tree;
  • link_type – link type of the item;
  • status – status of the item;
  • amount – quantity;
  • unit – unit of measure;
  • comment – comment;
  • price – price;
  • start_date – date of start;
  • start_time – time of start;
  • end_date – date of end;
  • end_time – time of end;
  • created_date – date of item creation;
  • change_date – date of item change;

Error codes

0 – No error;

1 – Error of rights;

2 – Error of data receiving;

3 – Error of request data.

Leave a Reply