JavaScript: Difference between revisions

From SMTX Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
The CommonInterface package supports a number of basic java functions that can be used in all javascript functions within SSP.
The CommonInterface package supports a number of basic java functions that can be used in all javascript functions within SSP.


=== logDebug ===
=== Common Functions ===
==== logDebug ====
logs entry into the physical logfile of the Common application
logs entry into the physical logfile of the Common application
  CommonInterface.logDebug('message');
  CommonInterface.logDebug('message');
  ''returns'': nothing
  ''returns'': nothing
=== Get the hash of a string ===
first parameter is the type of hash, can be: sha1, sha1_base64, sha256, sha256_base64, sha512 or sha512_base64
CommonInterface.getHash('sha512', 'test');
''returns'': EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF
=== encrypts string ===
first parameter is the password (if empty the default one is used)
CommonInterface.encrypt('test', 'mypassword');
''returns'': oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=
=== decrypts string ===
first parameter is the password (if empty the default one is used)
CommonInterface.decrypt('oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=', 'mypassword');
''returns'': test
=== generate a new guid ===
CommonInterface.newGuid();
''returns'': a new guid (eg 9ec5d882-dcb7-408b-9638-c4f05045f18c)


=== Convert text to base64 ===
=== Conversion ===
==== Convert text to base64 ====
Converts a string into a base64 encoded string
Converts a string into a base64 encoded string
  CommonInterface.convertToBase64('test');
  CommonInterface.convertToBase64('test');
  ''returns'': dGVzdA==
  ''returns'': dGVzdA==
   
   
=== Convert base64 to string ===
==== Convert base64 to string ====
Converts a string that is base64 encoded into a readable string
Converts a string that is base64 encoded into a readable string
  CommonInterface.convertFromBase64('dGVzdA==');
  CommonInterface.convertFromBase64('dGVzdA==');
  ''returns'': test
  ''returns'': test
   
   
=== htmlencode text ===
==== htmlencode text ====
Encodes text that contains html code into encoded html so that the html code is displayed in a browser. This function can be used to avoid the execution of input strings.
Encodes text that contains html code into encoded html so that the html code is displayed in a browser. This function can be used to avoid the execution of input strings.
  CommonInterface.htmlEncode('<strong>test</strong>');
  CommonInterface.htmlEncode('<strong>test</strong>');
  ''returns'': &lt;strong&gt;test&lt;/strong&gt;
  ''returns'': &lt;strong&gt;test&lt;/strong&gt;
   
   
=== htmldecode text ===
==== htmldecode text ====
Converts encoded html into default html
Converts encoded html into default html
  CommonInterface.htmlDecode('&lt;strong&gt;test&lt;/strong&gt;');
  CommonInterface.htmlDecode('&lt;strong&gt;test&lt;/strong&gt;');
  ''returns'': <strong>test</strong>
  ''returns'': <strong>test</strong>
   
   
=== urlencode text ===
==== urlencode text ====
Encodes a string into a url encoded string.
Encodes a string into a url encoded string.
  CommonInterface.urlEncode('?param1=test1&param2=test2');
  CommonInterface.urlEncode('?param1=test1&param2=test2');
  ''returns'': %3fparam1%3dtest1%26param2%3dtest2
  ''returns'': %3fparam1%3dtest1%26param2%3dtest2
   
   
=== urldecode text ===
==== urldecode text ====
Decodes a url encoded string into a readable format
Decodes a url encoded string into a readable format
  CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
  CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
  ''returns'': ?param1=test1&param2=test2
  ''returns'': ?param1=test1&param2=test2
   
   
=== xmlencode text ===
==== xmlencode text ====
Encodes a text string into proper XML characters
Encodes a text string into proper XML characters
  CommonInterface.xmlEncode('test1 & test2');
  CommonInterface.xmlEncode('test1 & test2');
  ''returns'': test1 &amp; test2
  ''returns'': test1 &amp; test2
   
   
=== Remove invalid characters ===
==== Remove invalid characters ====
remove invalid (weird characters, mostly from pasting from other soures) xml characters:
remove invalid (weird characters, mostly from pasting from other soures) xml characters:
  CommonInterface.stripNonValidXMLCharacters ('♦≡╬▌test1'};
  CommonInterface.stripNonValidXMLCharacters ('♦≡╬▌test1'};
  ''returns'': test1
  ''returns'': test1


=== Convert bbcode to html ===
==== Convert bbcode to html ====
Convert bb-code in html formatted text, to include bb-code formatted text on web pages.
Convert bb-code in html formatted text, to include bb-code formatted text on web pages.
  CommonInterface.bbCodeToHtml('[b]test[/b]');
  CommonInterface.bbCodeToHtml('[b]test[/b]');
  ''returns'': <strong>test</strong>
  ''returns'': <strong>test</strong>
   
   
=== Convert bbcode to text ===
==== Convert bbcode to text ====
Convert bb-code into standard text by removing all codes
Convert bb-code into standard text by removing all codes
  CommonInterface.bbCodeToText('[b]test[/b]');
  CommonInterface.bbCodeToText('[b]test[/b]');
  ''returns'': test
  ''returns'': test
=== File Management ===
=== Check if the input is a valid path (url or local path) ===
==== Check if the input is a valid path (url or local path) ====
Checks if the provided path is valid. Returns 1 or 0
Checks if the provided path is valid. Returns 1 or 0
  CommonInterface.isValidPath('D:\\test.txt');
  CommonInterface.isValidPath('D:\\test.txt');
Line 65: Line 85:
  ''returns'': boolean
  ''returns'': boolean
   
   
=== Check if the url starts with the url (public or local) to ssp ===
==== Check if the url starts with the url (public or local) to ssp ====
  CommonInterface.isSspFile('http://dev.ssp7.company.com/test.txt');
  CommonInterface.isSspFile('http://dev.ssp7.company.com/test.txt');
  ''returns'': boolean
  ''returns'': boolean
   
   
=== Local path of url ===
==== Local path of url ====
returns local path to the file for a provided url (only in case the URL point to an ssp file)
returns local path to the file for a provided url (only in case the URL point to an ssp file)
  CommonInterface.getLocalPathForSspFile('http:=== dev.ssp7.company.com/test.txt');
  CommonInterface.getLocalPathForSspFile('http:=== dev.ssp7.company.com/test.txt');
  ''returns'': C:\Websites\dev.ssp7.company.com\Sql.Dev.Ssp7\test.txt
  ''returns'': C:\Websites\dev.ssp7.company.com\Sql.Dev.Ssp7\test.txt
   
   
=== Get the filename of the url / local path ===
==== Get the filename of the url / local path ====
retrieves the file name that is part of a url
retrieves the file name that is part of a url
  CommonInterface.getFileName('http://dev.ssp7.company.com/test.txt');
  CommonInterface.getFileName('http://dev.ssp7.company.com/test.txt');
  ''returns'': test.txt
  ''returns'': test.txt
   
   
=== Get the file extension of the url / local path ===
==== Get the file extension of the url / local path ====
Retrieves the extension of the file provided as argument
Retrieves the extension of the file provided as argument
  CommonInterface.getFileExtension('http://dev.ssp7.company.com/test.txt');
  CommonInterface.getFileExtension('http://dev.ssp7.company.com/test.txt');
  ''returns'': .txt
  ''returns'': .txt
   
   
=== Get the file content of the url / local path ===
==== Get the file content of the url / local path ====
Downloads the file provided as argument and returns the file contents
Downloads the file provided as argument and returns the file contents
  CommonInterface.getFileContent('http:=== dev.ssp7.company.com/test.txt');
  CommonInterface.getFileContent('http:=== dev.ssp7.company.com/test.txt');
  ''returns'': test content
  ''returns'': test content
   
   
=== Get the file content in base 64 of the url / local path ===
==== Get the file content in base 64 of the url / local path ====
  CommonInterface.getFileContentInBase64('http:=== dev.ssp7.company.com/test.txt');
  CommonInterface.getFileContentInBase64('http:=== dev.ssp7.company.com/test.txt');
  ''returns'': dGVzdCBjb250ZW50
  ''returns'': dGVzdCBjb250ZW50
   
   
=== Get the file size in bytes of the url / local path ===
==== Get the file size in bytes of the url / local path ====
  CommonInterface.getFileSizeInBytes('http:=== dev.ssp7.company.com/test.txt');
  CommonInterface.getFileSizeInBytes('http:=== dev.ssp7.company.com/test.txt');
  ''returns'': 12
  ''returns'': 12
   
   
=== Format file size in readable format (with B, KB, MB, GB or TB) ===
==== Format file size in readable format (with B, KB, MB, GB or TB) ====
Converts the provided number of bytes into a readable file size
Converts the provided number of bytes into a readable file size
  CommonInterface.formatFileSizeInBytes(5242880);
  CommonInterface.formatFileSizeInBytes(5242880);
  ''returns'': 5 MB
  ''returns'': 5 MB
   
   
=== Get the hash of a string ===
first parameter is the type of hash, can be: sha1, sha1_base64, sha256, sha256_base64, sha512 or sha512_base64
CommonInterface.getHash('sha512', 'test');
''returns'': EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF
=== encrypts string ===
first parameter is the password (if empty the default one is used)
CommonInterface.encrypt('test', 'mypassword');
''returns'': oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=
=== decrypts string ===
first parameter is the password (if empty the default one is used)
CommonInterface.decrypt('oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=', 'mypassword');
''returns'': test
=== generate a new guid ===
CommonInterface.newGuid();
''returns'': a new guid (eg 9ec5d882-dcb7-408b-9638-c4f05045f18c)
== CommonInterface - Calling Web Services ==
== CommonInterface - Calling Web Services ==
=== Get or send data to or from a webservice defined under adapters
=== Get or send data to or from a webservice defined under adapters

Revision as of 21:29, 28 February 2021

Since version 7.20.10 SSP supports javascript steps in the workflow. Below is a summary of all SSP specific functions, available to be used within the step:

CommonInterface

The CommonInterface package supports a number of basic java functions that can be used in all javascript functions within SSP.

Common Functions

logDebug

logs entry into the physical logfile of the Common application

CommonInterface.logDebug('message');
returns: nothing

Get the hash of a string

first parameter is the type of hash, can be: sha1, sha1_base64, sha256, sha256_base64, sha512 or sha512_base64

CommonInterface.getHash('sha512', 'test');
returns: EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF

encrypts string

first parameter is the password (if empty the default one is used)

CommonInterface.encrypt('test', 'mypassword');
returns: oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=

decrypts string

first parameter is the password (if empty the default one is used)

CommonInterface.decrypt('oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=', 'mypassword');
returns: test

generate a new guid

CommonInterface.newGuid();
returns: a new guid (eg 9ec5d882-dcb7-408b-9638-c4f05045f18c)

Conversion

Convert text to base64

Converts a string into a base64 encoded string

CommonInterface.convertToBase64('test');
returns: dGVzdA==

Convert base64 to string

Converts a string that is base64 encoded into a readable string

CommonInterface.convertFromBase64('dGVzdA==');
returns: test

htmlencode text

Encodes text that contains html code into encoded html so that the html code is displayed in a browser. This function can be used to avoid the execution of input strings.

CommonInterface.htmlEncode('test');
returns: <strong>test</strong>

htmldecode text

Converts encoded html into default html

CommonInterface.htmlDecode('<strong>test</strong>');
returns: test

urlencode text

Encodes a string into a url encoded string.

CommonInterface.urlEncode('?param1=test1&param2=test2');
returns: %3fparam1%3dtest1%26param2%3dtest2

urldecode text

Decodes a url encoded string into a readable format

CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
returns: ?param1=test1&param2=test2

xmlencode text

Encodes a text string into proper XML characters

CommonInterface.xmlEncode('test1 & test2');
returns: test1 & test2

Remove invalid characters

remove invalid (weird characters, mostly from pasting from other soures) xml characters:

CommonInterface.stripNonValidXMLCharacters ('♦≡╬▌test1'};
returns: test1

Convert bbcode to html

Convert bb-code in html formatted text, to include bb-code formatted text on web pages.

CommonInterface.bbCodeToHtml('[b]test[/b]');
returns: test

Convert bbcode to text

Convert bb-code into standard text by removing all codes

CommonInterface.bbCodeToText('[b]test[/b]');
returns: test

File Management

Check if the input is a valid path (url or local path)

Checks if the provided path is valid. Returns 1 or 0

CommonInterface.isValidPath('D:\\test.txt');
CommonInterface.isValidPath('http://dev.ssp7.company.com/test.txt');
returns: boolean

Check if the url starts with the url (public or local) to ssp

CommonInterface.isSspFile('http://dev.ssp7.company.com/test.txt');
returns: boolean

Local path of url

returns local path to the file for a provided url (only in case the URL point to an ssp file)

CommonInterface.getLocalPathForSspFile('http:=== dev.ssp7.company.com/test.txt');
returns: C:\Websites\dev.ssp7.company.com\Sql.Dev.Ssp7\test.txt

Get the filename of the url / local path

retrieves the file name that is part of a url

CommonInterface.getFileName('http://dev.ssp7.company.com/test.txt');
returns: test.txt

Get the file extension of the url / local path

Retrieves the extension of the file provided as argument

CommonInterface.getFileExtension('http://dev.ssp7.company.com/test.txt');
returns: .txt

Get the file content of the url / local path

Downloads the file provided as argument and returns the file contents

CommonInterface.getFileContent('http:=== dev.ssp7.company.com/test.txt');
returns: test content

Get the file content in base 64 of the url / local path

CommonInterface.getFileContentInBase64('http:=== dev.ssp7.company.com/test.txt');
returns: dGVzdCBjb250ZW50

Get the file size in bytes of the url / local path

CommonInterface.getFileSizeInBytes('http:=== dev.ssp7.company.com/test.txt');
returns: 12

Format file size in readable format (with B, KB, MB, GB or TB)

Converts the provided number of bytes into a readable file size

CommonInterface.formatFileSizeInBytes(5242880);
returns: 5 MB

CommonInterface - Calling Web Services

=== Get or send data to or from a webservice defined under adapters first parameter: name of webservice second parameter: object with key / value that is used as input fields)

CommonInterface.callWebservice('Name of webservice', { 'field1': 'value1', 'field2': 'value2' });
returns in case of the webservice having a return type of single value: the single value (string)
returns in case of the webservice having a return type of datatable or valuelist: the object encoded as a JSON string. If you want to consume it as an object in your javascript, you must use 
JSON.parse(), eg in one line: JSON.parse(CommonInterface.callWebservice('Name of webservice', { 'field1': 'value1', 'field2': 'value2' }));

Datastore parameters

 
=== get all the entries of a parameter:
=== first parameter: name of the parameter
 CommonInterface.getAllParameterEntries('Address Book');
=== returns all the entries (array) with all the fields (properties) as JSON encoded string. If you want to consume it, use JSON.parse, eg: JSON.parse(CommonInterface.getAllParameterEntries('Address Book'));
 
=== get all the entries of a parameter sorted on a field:
=== first parameter: name of the parameter
=== second parameter: field to sort on
 CommonInterface.getAllParameterEntriesAndSort('Address Book', 'Name');
=== returns same as above but sorted via the query
 
=== get the count of all the entries of a parameter:
=== first parameter: name of the parameter
 CommonInterface.getAllParameterEntryCount('Address Book');
 ''returns'': 9
 
=== gets the specific value of a field for a specific entry
=== first parameter: name of the parameter
=== second parameter: key field
=== third parameter: key value
=== fourth parameter: fields to return, joined by double pipes
 CommonInterface.getParameterEntryValue('Address Book', 'Email', 'john@company.com', 'Name||Location');
=== returns the values if the requested fields for the first entry found, joined by double pipe, eg: john Crijnen||Maastricht
 
=== gets the all values of a field in a parameter
=== first parameter: name of the parameter
=== second parameter: field name
 CommonInterface.getParameterEntryValues('Address Book', 'Email');
=== returns a JSON encoded string of all the values (sorted), again to consume use JSON.parse, result: ["dasy@company.com","donald@company.com","john@company.com","test@gmail.com"]
 
=== advanced search on parameter entries:
=== first parameter: name of the parameter
=== second parameter: object with key / value containing the predicates
 CommonInterface.searchParameterEntries('Address Book', [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'gmail.com' },{ connector: 'or', subfilter: [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'company' }, { fieldname: 'Email', filteroperator: 'notcontains', filtervalue: 'john' } ]}]);
 ''returns'': see CommonInterface.getAllParameterEntries
 
=== advanced search and sort on parameter entries:
=== first parameter: name of the parameter
=== second parameter: object with key / value containing the predicates
=== third parameter: field to sort on
 CommonInterface.searchParameterEntriesAndSort('Address Book', [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'gmail.com' },{ connector: 'or', subfilter: [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'company' }, { fieldname: 'Email', filteroperator: 'notcontains', filtervalue: 'john' } ]}], 'Location');
 ''returns'': same as CommonInterface.searchParameterEntries but sorted via the query
 
=== gets the result count of an advanced search:
=== first parameter: name of the parameter
=== second parameter: object with key / value containing the predicates
 CommonInterface.searchParameterEntryCount('Address Book', [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'gmail.com' },{ connector: 'or', subfilter: [{ fieldname: 'Email', filteroperator: 'contains', filtervalue: 'company' }, { fieldname: 'Email', filteroperator: 'notcontains', filtervalue: 'john' } ]}]);
=== returns the number of records found
 
=== adds a parameter entry
=== first parameter: name of the parameter
=== second parameter: object with key / value that contains the fields (keys) with the values (values)
 CommonInterface.addParameterEntry('Address Book', { 'Name': 'Test', 'Email': 'test@company.com' });
=== returns the new internal id of the entry
 
=== updates zero or more parameter entries
=== first parameter: name of the parameter
=== second parameter: object with key / value that represents the predicate (filter)
=== third parameter: object with key / value that contains the new values (not all values are required)
 CommonInterface.updateParameterEntries('Address Book', { 'Email': 'test@company.com' }, { 'Name': 'Test updated' });
=== returns the number of entries updated (make sure you use the correct filter, you could potentially update all the entries)
 
=== deletes zero or more parameter entries
=== first parameter: name of the parameter
=== second parameter: object with key / value that represents the predicate (filter)
 CommonInterface.deleteParameterEntries('Address Book', { 'Email': 'test@company.com' });
=== returns the number of entries deleted (make sure you use the correct filter, you could potentially delete all the entries)
 
 

Workflow Interface

 
 
=== gets the value of a variable in a ticket
=== first parameter: ticket id
=== second parameter: name of the variable
WorkflowInterface.getVariableValue(1500, 'My variable');
=== returns the value as string
 
=== sets the value of a variable in a ticket (if it doesn't exists, it will be created)
=== first parameter: ticket id
=== second parameter: name of the variable
=== third parameter: value of the variable
WorkflowInterface.setVariableValue(1500, 'My variable', 'new value');
=== returns nothing
 
=== gets the raw value of a form field in a ticket
=== first parameter: ticket id
=== second parameter: internal name of the form field
WorkflowInterface.getFormFieldValue(1500, 'MyFormField');
=== returns the value as string
 
=== gets the raw displayvalue of a form field in a ticket
=== first parameter: ticket id
=== second parameter: internal name of the form field
WorkflowInterface.getFormFieldDisplayValue(1500, 'MyFormField');
=== returns the display value as string
 
=== adds a log to the process instance (workflow log)
=== first parameter: ticket id
=== second parameter: the log text
WorkflowInterface.addWorkflowLog(1500, 'My log text');
=== returns nothing

=== Adds document to a ticket
WorkflowInterface.addDocument(ticketid, 'pathtofile', hideinworkflow); 
=== hideinworkflow = boolean

=== Adds document to a ticket with a specific name
WorkflowInterface.addDocumentWithFileName(ticketid, 'pathtofile', 'filenametoshow', hideinworkflow); 
=== hideinworkflow = boolean

=== Deletes all currently linked documents from a ticket.
WorkflowInterface.deleteAllDocuments(ticketid); 

Update Ticketing fields

 

=== Adds a public note within ticketing
WorkflowInterface.addPrivateNote(ticketid, personidoremail, logtext);

=== Adds a private message within ticketing
WorkflowInterface.addPublicMessage(ticketid, personidoremail, logtext);

=== Adds a ticket change entry within ticketing
WorkflowInterface.addTicketChange(ticketid, personidoremail, logtext);
=== This action will not send an email message

=== Update ticket fields
WorkflowInterface.updateTicketFields(ticketid, fields);
fields: json object with a key field to set which field should be updated, together with the new value for example: WorkflowInterface.updateTicketFields(ticketid, {"Status": "Open", "Custom": {"Field01": "Value01" }});

=== Possible fields: LockTicket, TicketIsRunning, Classification, Status, Description, Information, AssignedToPerson, AssignedToPersonGroup, Category, Medium, Priority, Service, Solution, ClosureCode, Custom, Requestor, RequestedFor, Pool, PlannedDeliveryDate, DeadlineDate, RequestedForAlternateName, RequestedForAlternateEmail, RequestedForAlternateTelephone, SolutionLinkAllDocuments, RequestedForTeam,
WorkflowPool, TicketType, TasksType, RemoveOnDate

=== Lock ticket
WorkflowInterface.lockTicket(ticketid);

=== Unlock ticket
WorkflowInterface.unlockTicket(ticketid);

=== Set ticket to IsRunning = True
WorkflowInterface.enableTicketIsRunning(ticketid);

=== Set ticket to IsRunning = False
WorkflowInterface.disableTicketIsRunning(ticketid);

===  Create a new, blank Task within a ticket
WorkflowInterface.addTask(ticketid, fields); 
=== returns the new task id

=== Update fields of a task
WorkflowInterface.updateTask(ticketid, taskid, fields);
fields: json object with a key field to set which field should be updated, together with the new value for example: WorkflowInterface.updateTask(ticketid, taskid, {"Status": "Open","Description":"My descriptionb" });

=== Possible fields: Description, AssignedToPersonGroup, AssignedToPerson, DeliveryDate, Information, Solution, LockedTicket, IsCompleted, ExternalReference, ExternalResolved, LinkAllTicketDocuments, Status, Priority, DeadlineDate 

|Example Javascript