Exploring code generation
-
- UpdatedAug 1, 2024
- 2 minutes to read
- Xanadu
- Building applications
Learn about how AI-generated code can empower developers scripting on the ServiceNow AI Platform.
Code generation overview
Now Assist for Creator activates the code generation skill. With code generation, you provide text describing the code to generate and get code suggestions in the JavaScript editor on forms in the ServiceNow AI Platform and in Script steps in Workflow Studio. Developers with varying levels of experience in scripting on the ServiceNow AI Platform can benefit from using code generation to get started writing custom scripts or iterate on scripts more efficiently.
To generate code suggestions, you describe the goal of the code to generate in the Code with Now Assist dialog box. The code suggestion appears in the lines following your prompt but isn’t added to your script until it's accepted.
Code generation workflow
- From the script editor, a developer opens the Code with Now Assist dialog box and describes the code they want to generate.
- The developer triggers generating a code suggestion.
In the following example, a developer describes what they want the script to do in the Code with Now Assist dialog box. The code suggestion appears highlighted in the script editor.
- The developer reviews the AI-generated code suggestion and either accepts or rejects it.
- If they accept it, the code is added to the script, and they can make any necessary edits based on their review.
- If they reject it, the code isn’t added to the script, and they can rephrase their prompt to generate a new code suggestion.
In the following example, a line next to the line numbers indicates which code was created by AI and hasn't been edited. If you edit AI-generated code, the line indicator doesn’t appear for those lines of code.Figure 1. AI-generated code lines
Optionally, you can turn on code completion functionality to use code or single-shot prompts in script editors with Now Assist for code generation.
Code generation benefits
Benefit | Feature | Users |
---|---|---|
Improve quality of scripts, automate repetitive coding tasks, and reduce time spent searching for or recalling code | Text-to-code and code complete | Developers |
Iterate on scripts efficiently | Code editing | Developers |
Identify code generated by AI | Tracking AI-generated code | Developers, administrators |