- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Once installed, Now Assist for Code is ready to use. However, to get the most out of it, you need to know where to use it and how to structure a good prompt. The following information showcases some key information on how to use Now Assist for Code and some use cases to showcase its power.
The following prompts and use cases will help you showcase the power of Now Assist for Code. If you have other use cases and prompts that should be added here, please let us know.
Currently, it is only available on standard script fields on forms, but support will be added shortly for other script fields like those in Flow Designer.
Usage Tips
Comment to Code
At the end of a comment block, press control + enter to create the code.
Comment Format
Comments can be either single line (recommended) or multiple lines. When using multiple lines, make sure the cursor is after the close comment (*/).
Code Completion
While writing a comment will build an entire code block, you can call the prediction at any time to complete the code you are working on.
In this example, the system understands getDayOfTheWeek and completes the cases expecting an option for each day of the week.
With a different setup, it will generate a different set of case statements.
Completing Partial Code Results
Depending on the length of the code being generated, Now Assist for Code may not return the entire code needed. If this occurs, move your cursor to the end of the generated code and press control + enter again to generate the additional code. Repeat as needed.
Example Prompts
While text-to-code and code completion are very versatile, there are places where it really shines in the ServiceNow environment.
These include:
- Context Awareness
- API Calls
Context Awareness
Now Assist for Code generates context-aware code that is specific to the script editor that it is being called from and the code that comes before the prompt. Certain script fields have access to special contexts and libraries which require this knowledge about this context to produce the appropriate code.
For example, when calling Text-to-Code in an Instance Scan Check, it knows to leverage the Instance Scan engine variable which is only available in Instance Scan. The same prompt in an Email Script will produce a different recommendation based on where it is called and the seed code.
Here are some examples where we give the script the same comment:
// identify inactive users who are locked out
Action Designer (in Flow Designer)
Here we see that the script knows to output the results to an “outputs.” variable.
Instance Scan
In an Instance Scan check, we know to leverage the "engine" object.
Fix Script
Fix scripts are very simple scripts with no special objects. However, text-to-code will generate a this as a function to make it easy to use it later in the script.
Business Rule
While this is similar to the Fix Script output, this version is not enclosed in a function as that is not common for a Business Rule.
Email Script
An Email Script knows to output the information with the template object and to leverage the email object.
API Calls
API calls provide a very resilient way to work with ServiceNow, however, developers often have to look up the reference on what common parameters are. Text-to-Code greatly reduces the time for this.
FlowAPI
Prompt: // execute the DoSomething flow in the foreground with the parameters of a is 1 and b is the current user
RestMessageV2
Prompt: // make a rest call to example.com
GlideSysAttachment
Prompt: // get a list of the current attachments
Use Cases
Actions
Text-to-code complements our low-code strategy. The best way to demonstrate that is by showing how text-to-code can help a pro-coder quickly and easily create new actions that can be consumed in Flow Designer. Starting with a comment, we can create the heart of our action and then map the inputs and outputs as needed. Note that the script does not currently (as of Vancouver) take into the variables you have defined so it may be easier to start with the script then create the inputs and outputs to match.
Script Includes
Utility Functions for Dynamic Filter Options
This will be great for dynamic filter options which empower developers to make reporting easier, more efficient, and more dynamic.
Prompt: // get the callers from all active p1 incidents
Fix Scripts
Fix scripts are a common way to correct existing data when a change is made. These are most often designed to be run one time and need to be quick and efficient. Text-to-Code lets you describe what data you want to fix and fix it very quickly.
- 8,397 Views
- « Previous
-
- 1
- 2
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.