Issue Summary:
When using Digi in a ServiceNow script field, typing @digi and pressing TAB initiates a request that never completes. The request remains in the "New" state and is not processed. This appears to be due to a malformed JSON error in the DigiAPI script include, triggered by double quotes within a configured AI Prompt.
When using the OpenAI - 1.0.3 AI Engine and gpt-3.5-turbo model.
Steps to Reproduce:
-
In a script field, type @digi <your request>, then press TAB.
-
Observe the "Processing Digi Request" modal remains indefinitely.
- The corresponding Request (x_radi_digi_request) remains in the
New state.
- Run the following background script to attempt to manually process the request:
var reqId = '<request_sys_id>';
var digiReq = new x_radi_digi.DigiRequest(reqId);
digiReq.process();
- The following error is thrown:
Script execution error: Script Identifier: null.null.script, Error Description: Unexpected token in object literal
Evaluator: com.glide.script.RhinoEcmaError: Unexpected token in object literal
at sys_script_include.9797c7c41b3e2110d4e599f91d4bcb21.script:128 (_getParamValue)
Root Cause:
The error occurs in the DigiAPI Script Include, in the _getParamValue method:
if (paramType === 'array') {
var anArr = JSON.parse(paramValue);
return anArr;
}
In this case, an AI Prompt (x_radi_digi_ai_prompt) contains unescaped quotes (") in the Text field:
Type: Format
Text: If the answer includes javascript code, begin the code block with "<getBlockDelimiterBegin>" and end the code block with "<getBlockDelimiterEnd>".
Proposed Solution:
Handle unescaped quotes when replacing the <getPrompt> embedding.
In DigiAIModel Script Include --> _replaceEmbeddedValues(aString, prompt)
if (strSource.indexOf('<getPrompt>')) {
if(prompt && typeof prompt === 'string'){
// Escape quotes in the prompt to prevent JSON parsing errors
prompt = prompt
.replace(/\\"/g, "__ESCAPED_QUOTE__") // preserve already escaped quotes
.replace(/"/g, '\\"')
.replace(/__ESCAPED_QUOTE__/g, '\\"');
}
aString = aString.replace('<getPrompt>', prompt);
}

Issue Summary:
When using Digi in a ServiceNow script field, typing
@digiand pressing TAB initiates a request that never completes. The request remains in the "New" state and is not processed. This appears to be due to a malformed JSON error in the DigiAPI script include, triggered by double quotes within a configured AI Prompt.When using the OpenAI - 1.0.3 AI Engine and
gpt-3.5-turbomodel.Steps to Reproduce:
In a script field, type
@digi <your request>, then press TAB.Observe the "Processing Digi Request" modal remains indefinitely.
Newstate.Root Cause:
The error occurs in the
DigiAPIScript Include, in the_getParamValuemethod:In this case, an AI Prompt (x_radi_digi_ai_prompt) contains unescaped quotes (") in the Text field:
Proposed Solution:
Handle unescaped quotes when replacing the
<getPrompt>embedding.In DigiAIModel Script Include -->
_replaceEmbeddedValues(aString, prompt)