JavaScript

From SMTX Wiki
Revision as of 21:00, 28 February 2021 by Smtxwiki (talk | contribs)
Jump to navigation Jump to search

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

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: CommonInterface.htmlEncode('test'); //returns: <strong>test</strong>

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

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

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

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

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

//converts bbcode to html: CommonInterface.bbCodeToHtml('[b]test[/b]'); //returns: test

//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)

//Strip invalid XML characters from a string CommonInterface.stripNonValidXMLCharacters('text'); //returns: string

</nowiki>

Calling Web Services

 
//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