Configure Lens launcher using scripted screen
Configure a ServiceNow AI Lens launcher button with scripted screen.
The following example adds a button instance to the “top-icon” location of the scripted screen. The highlighted portions indicate the updates needed in an existing scripted screen to add the ServiceNow AI Lens Launcher button.
(function ScriptedScreen(input, result) {
var builder = new sn_scripted_screen.ParameterScreenBuilder("scripted_screen_incident", "Edit Incident Scr");
builder.nextLabel = gs.getMessage("Next");
builder.previousLabel = gs.getMessage("Previous");
builder.cancelLabel = gs.getMessage("Cancel");
builder.submitLabel = gs.getMessage("Submit");
var variableBuilder = new sn_scripted_screen.VariableBuilder("v_short_description", "db_field");
variableBuilder.addAttribute("FieldName", "short_description");
var buttonInstanceBuilder = new sn_scripted_screen.ButtonInstanceBuilder("a719743e0f703210e83019e800d1b29d", "Lens Launcher", "top_icon");
buttonInstanceBuilder.icon = "76d03b43ff6c721057e9ffffffffff1f";
var inputBuilder = new sn_scripted_screen.InputBuilder("short_description", "string", "Short Descrition");
inputBuilder.autofillVariable(variableBuilder);
builder.addInput(inputBuilder);
builder.addButtonInstance(buttonInstanceBuilder);
builder.addVariable(variableBuilder);
builder.presentationStyle = "screen";
builder.advancedPagination = "true";
result.screenBuilder = builder;
return result;
})(input, result);
In this example, a719743e0f703210e83019e800d1b29d is the sys_id of the sys_sg_button of type lens_launcher. The button must be created declaratively.
76d03b43ff6c721057e9ffffffffff1f is the sys_id of the sys_sg_icon.
PresentationStyle should be screen to support a button instance on an input form screen or scripted screen.
The third parameter in ButtonInstanceBuilder() is the location. The location can be either top_icon or top.