JavaScript: Difference between revisions

From SMTX Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
==== logDebug ====
==== logDebug ====
logs entry into the physical logfile of the Common application
logs entry into the physical logfile of the Common application
#First parameter is the message to be added to the common log
  CommonInterface.logDebug('message');
  CommonInterface.logDebug('message');
  ''returns'': nothing
  ''returns'': nothing
==== Get the hash of a string ====
==== 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
first parameter is the type of hash, can be: sha1, sha1_base64, sha256, sha256_base64, sha512 or sha512_base64
#second parameter is the string to be hashed
  CommonInterface.getHash('sha512', 'test');
  CommonInterface.getHash('sha512', 'test');
  ''returns'': EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF
  ''returns'': EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF
   
   
==== encrypts string ====
==== encrypts string ====
first parameter is the password (if empty the default one is used)
#first parameter is the password (if empty the default one is used)
#second parameter is the string to be encrypted
  CommonInterface.encrypt('test', 'mypassword');
  CommonInterface.encrypt('test', 'mypassword');
  ''returns'': oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=
  ''returns'': oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=
   
   
==== decrypts string ====
==== decrypts string ====
first parameter is the password (if empty the default one is used)
#first parameter is the password (if empty the default one is used)
  CommonInterface.decrypt('oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=', 'mypassword');
  CommonInterface.decrypt('oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=', 'mypassword');
  ''returns'': test
  ''returns'': test
Line 31: Line 34:
==== Convert text to base64 ====
==== Convert text to base64 ====
Converts a string into a base64 encoded string
Converts a string into a base64 encoded string
#First parameter is the string to be converted
  CommonInterface.convertToBase64('test');
  CommonInterface.convertToBase64('test');
  ''returns'': dGVzdA==
  ''returns'': dGVzdA==
Line 36: Line 40:
==== 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
#first parameter  is the string to be decoded
  CommonInterface.convertFromBase64('dGVzdA==');
  CommonInterface.convertFromBase64('dGVzdA==');
  ''returns'': test
  ''returns'': test
Line 41: Line 46:
==== 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.
#first parameter is the string to be encoded
  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;
Line 46: Line 52:
==== htmldecode text ====
==== htmldecode text ====
Converts encoded html into default html
Converts encoded html into default html
#first parameter is the html string to be converted
  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>
Line 51: Line 58:
==== urlencode text ====
==== urlencode text ====
Encodes a string into a url encoded string.
Encodes a string into a url encoded string.
#first parameter is the text to be encoded
  CommonInterface.urlEncode('?param1=test1&param2=test2');
  CommonInterface.urlEncode('?param1=test1&param2=test2');
  ''returns'': %3fparam1%3dtest1%26param2%3dtest2
  ''returns'': %3fparam1%3dtest1%26param2%3dtest2
Line 56: Line 64:
==== urldecode text ====
==== urldecode text ====
Decodes a url encoded string into a readable format
Decodes a url encoded string into a readable format
#first parameter is the string to be decoded
  CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
  CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
  ''returns'': ?param1=test1&param2=test2
  ''returns'': ?param1=test1&param2=test2
Line 61: Line 70:
==== xmlencode text ====
==== xmlencode text ====
Encodes a text string into proper XML characters
Encodes a text string into proper XML characters
#first parameter is the string to be encoded
  CommonInterface.xmlEncode('test1 & test2');
  CommonInterface.xmlEncode('test1 & test2');
  ''returns'': test1 &amp; test2
  ''returns'': test1 &amp; test2
   
   
==== Remove invalid characters ====
==== Remove invalid characters ====
#first parameter is the string that contains non-standard 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'};
Line 71: Line 82:
==== 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.
#first parameter is the bbcode that should be converted into HTML
  CommonInterface.bbCodeToHtml('[b]test[/b]');
  CommonInterface.bbCodeToHtml('[b]test[/b]');
  ''returns'': <strong>test</strong>
  ''returns'': <strong>test</strong>
Line 76: Line 88:
==== 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
#first parameter is the bbcode to be converted into text
  CommonInterface.bbCodeToText('[b]test[/b]');
  CommonInterface.bbCodeToText('[b]test[/b]');
  ''returns'': test
  ''returns'': test
=== File Management ===
=== 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) ====
Line 122: Line 136:
  ''returns'': 5 MB
  ''returns'': 5 MB
   
   
== CommonInterface - Calling Web Services ==
=== 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 ====
first parameter: name of webservice
#first parameter: name of webservice
second parameter: object with key / value that is used as input fields)
#second parameter: object with key / value that is used as input fields)
  CommonInterface.callWebservice('Name of webservice', { 'field1': 'value1', 'field2': 'value2' });
  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 single value: the single value (string)
Line 131: Line 145:
  JSON.parse(), eg in one line: JSON.parse(CommonInterface.callWebservice('Name of webservice', { 'field1': 'value1', 'field2': 'value2' }));
  JSON.parse(), eg in one line: JSON.parse(CommonInterface.callWebservice('Name of webservice', { 'field1': 'value1', 'field2': 'value2' }));


== Datastore parameters ==
=== Datastore parameters ===
<nowiki>
 
=== get all the entries of a parameter:
==== get all entries of a parameter ===
=== first parameter: name of the parameter
#First parameter: name of the parameter
  CommonInterface.getAllParameterEntries('Address Book');
  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'));
''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:
=== get all entries of a parameter sorted on a field ===
=== first parameter: name of the parameter
#First parameter: name of the parameter
=== second parameter: field to sort on
#second parameter: field to sort on
  CommonInterface.getAllParameterEntriesAndSort('Address Book', 'Name');
  CommonInterface.getAllParameterEntriesAndSort('Address Book', 'Name');
=== returns same as above but sorted via the query
=== returns same as above but sorted via the query
   
   
=== get the count of all the entries of a parameter:
=== Get the count of all entries of a parameter ===
=== first parameter: name of the parameter
#first parameter: name of the parameter
  CommonInterface.getAllParameterEntryCount('Address Book');
  CommonInterface.getAllParameterEntryCount('Address Book');
  ''returns'': 9
  ''returns'': 9

Revision as of 21:38, 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

  1. First parameter is the message to be added to the common log
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

  1. second parameter is the string to be hashed
CommonInterface.getHash('sha512', 'test');
returns: EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF

encrypts string

  1. first parameter is the password (if empty the default one is used)
  2. second parameter is the string to be encrypted
CommonInterface.encrypt('test', 'mypassword');
returns: oOe3y182qDKOGzmFpfTiLzNpML+fyvwhfjA9HqF9OwYqcM/PZovosALARZzApNnvToKpBV1dsWnaDP7+iTBo/ic33ZwcxuNRlbGHiKDwdEY=

decrypts string

  1. 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

  1. First parameter is the string to be converted
CommonInterface.convertToBase64('test');
returns: dGVzdA==

Convert base64 to string

Converts a string that is base64 encoded into a readable string

  1. first parameter is the string to be decoded
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.

  1. first parameter is the string to be encoded
CommonInterface.htmlEncode('test');
returns: <strong>test</strong>

htmldecode text

Converts encoded html into default html

  1. first parameter is the html string to be converted
CommonInterface.htmlDecode('<strong>test</strong>');
returns: test

urlencode text

Encodes a string into a url encoded string.

  1. first parameter is the text to be encoded
CommonInterface.urlEncode('?param1=test1&param2=test2');
returns: %3fparam1%3dtest1%26param2%3dtest2

urldecode text

Decodes a url encoded string into a readable format

  1. first parameter is the string to be decoded
CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2');
returns: ?param1=test1&param2=test2

xmlencode text

Encodes a text string into proper XML characters

  1. first parameter is the string to be encoded
CommonInterface.xmlEncode('test1 & test2');
returns: test1 & test2

Remove invalid characters

  1. first parameter is the string that contains non-standard 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.

  1. first parameter is the bbcode that should be converted into HTML
CommonInterface.bbCodeToHtml('[b]test[/b]');
returns: test

Convert bbcode to text

Convert bb-code into standard text by removing all codes

  1. first parameter is the bbcode to be converted into text
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

Calling Web Services

Get or send data to or from a webservice defined under adapters

  1. first parameter: name of webservice
  2. 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 entries of a parameter

  1. 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 entries of a parameter sorted on a field

  1. First parameter: name of the parameter
  2. 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 entries of a parameter

  1. 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)


</nowiki>

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