JavaScript: Difference between revisions
No edit summary |
No edit summary |
||
| Line 49: | Line 49: | ||
''returns'': test1 | ''returns'': test1 | ||
=== | === 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 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 | ||
=== | === 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 65: | ||
''returns'': boolean | ''returns'': boolean | ||
=== | === 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 | ||
| Line 84: | Line 84: | ||
''returns'': .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'); | 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 === | ||
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 === | ||
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) === | ||
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 | first parameter is the type of hash, can be: sha1, sha1_base64, sha256, sha256_base64, sha512 or sha512_base64 | ||
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) | ||
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 | ||
=== generate a new guid | === generate a new guid === | ||
CommonInterface.newGuid(); | CommonInterface.newGuid(); | ||
''returns'': a new guid (eg 9ec5d882-dcb7-408b-9638-c4f05045f18c) | ''returns'': a new guid (eg 9ec5d882-dcb7-408b-9638-c4f05045f18c) | ||
=== | == CommonInterface - Calling Web Services == | ||
CommonInterface. | === Get or send data to or from a webservice defined under adapters | ||
''returns'': string | 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 == | == Datastore parameters == | ||
<nowiki> | <nowiki> | ||
Revision as of 21:26, 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.
logDebug
logs entry into the physical logfile of the Common application
CommonInterface.logDebug('message');
returns: nothing
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¶m2=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¶m2=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
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
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
=== 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