JavaScript: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 188: | Line 188: | ||
//second parameter: name of the variable | //second parameter: name of the variable | ||
//third parameter: value of the variable | //third parameter: value of the variable | ||
WorkflowInterface. | WorkflowInterface.setVariableValue(1500, 'My variable', 'new value'); | ||
//returns nothing | //returns nothing | ||
Revision as of 16:25, 22 December 2020
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 ****/ //log in the physical logfile: CommonInterface.logDebug('message'); //returns: nothing //convert text to base64: CommonInterface.convertToBase64('test'); //returns: dGVzdA== //convert base64 to string: CommonInterface.convertFromBase64('dGVzdA=='); //returns: test //htmlencode text: CommonInterface.htmlEncode('<strong>test</strong>'); //returns: <strong>test</strong> //htmldecode text: CommonInterface.htmlDecode('<strong>test</strong>'); //returns: <strong>test</strong> //urlencode text: CommonInterface.urlEncode('?param1=test1¶m2=test2'); //returns: %3fparam1%3dtest1%26param2%3dtest2 //urldecode text: CommonInterface.urlDecode('%3fparam1%3dtest1%26param2%3dtest2'); //returns: ?param1=test1¶m2=test2 //xmlencode text: CommonInterface.xmlEncode('test1 & test2'); //returns: test1 & test2 //converts bbcode to html: CommonInterface.bbCodeToHtml('[b]test[/b]'); //returns: <strong>test</strong> //converts bbcode to text: CommonInterface.bbCodeToText('[b]test[/b]'); //returns: test //checks if the input is a valid path (url or local path): CommonInterface.isValidPath('D:\\test.txt'); CommonInterface.isValidPath('http://dev.ssp7.company.com/test.txt'); //returns: boolean //checks if the url starts with the url (public or local) to ssp CommonInterface.isSspFile('http://dev.ssp7.company.com/test.txt'); //returns: boolean //returns to local path to the file for the url (in case it's an sspfile) CommonInterface.getLocalPathForSspFile('http://dev.ssp7.company.com/test.txt'); //returns: C:\Websites\dev.ssp7.company.com\Sql.Dev.Ssp7\test.txt //gets the filename of the url / local path CommonInterface.getFileName('http://dev.ssp7.company.com/test.txt'); //returns: test.txt //gets the file extension of the url / local path CommonInterface.getFileExtension('http://dev.ssp7.company.com/test.txt'); //returns: .txt //gets the file content of the url / local path CommonInterface.getFileContent('http://dev.ssp7.company.com/test.txt'); //returns: test content //gets the file content in base 64 of the url / local path CommonInterface.getFileContentInBase64('http://dev.ssp7.company.com/test.txt'); //returns: dGVzdCBjb250ZW50 //gets the file size in bytes of the url / local path CommonInterface.getFileSizeInBytes('http://dev.ssp7.company.com/test.txt'); //returns: 12 //formats the file size in readable format (with B, KB, MB, GB or TB) CommonInterface.formatFileSizeInBytes(5242880); //returns: 5 MB //gets 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) //call a webservice //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' })); //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) /**** WorkflowInterface ****/ //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