UI Action not triggering client script on Change Request form

nameisnani
Mega Sage

Hi Experts,

 

I am working on a requirement in ServiceNow to add a UI Action on the Change Request form that triggers a Copilot AI agent (Change Quality Advisor).

 

Requirement:
Add a button on the Change Request form which generates a prompt using the current change request details and opens a Microsoft Copilot AI agent in a new browser tab. The prompt should be copied to the clipboard so the user can paste it directly into Copilot for review.

 

Configuration Done:
• Created UI Action on table: change_request
• UI Action type: Form button
• Client checkbox: Enabled
• Onclick: openCopilotAgent();

 

Script used in UI Action:

 

function openCopilotAgent() {

var agentUrl = "https://copilot.microsoft.com/";

var number = g_form.getValue('number');
var sysId = g_form.getUniqueValue();
var link = window.location.href;

var prompt =
"You are Change Quality Advisor.\n" +
"Assess this ServiceNow Change Request and return:\n" +
"1) Quality score (0-10)\n" +
"2) Missing information\n" +
"3) Risk rating\n" +
"4) Suggested improvements\n\n" +
"Record:\n" +
"Number: " + number + "\n" +
"sys_id: " + sysId + "\n" +
"Link: " + link;

navigator.clipboard.writeText(prompt);

window.open(agentUrl, "_blank");

}

Issue:
When clicking the UI Action button, nothing happens. The Copilot page is not opening and the script does not appear to execute.

Troubleshooting done:
• Verified Client checkbox is enabled
• Verified Onclick function is configured
• Tested with condition set to true
• Tested in DEV instance

 

Question:


Is there any additional configuration required for client-side UI Actions to trigger window.open() or clipboard functions in ServiceNow forms?

 

Any guidance or suggestions would be appreciated.

 

Please help me here 

 

 

1 ACCEPTED SOLUTION

Tanushree Maiti
Kilo Patron

Hi @nameisnani ,

 

Why are your passing sys_id to the prompt, it is very internal . 

Somehow in Zurich PDI , window.open() not working ,it might be blocked by modern browser security policies.  

When it is replaced by g_navigation.openPopup , it is working .

Try it. On top of it fine tune the code as per your requirement.

function openCopilotAgent() {

 
 var agentUrl = "https://copilot.microsoft.com/";
var number = g_form.getValue('number');
var prompt =
"You are Change Quality Advisor.\n" +
"Assess this ServiceNow Change Request and return:\n" +
"1) Quality score (0-10)\n" +
"2) Missing information\n" +
"3) Risk rating\n" +
"4) Suggested improvements\n\n" +
"Record:\n" +
"Number: " + number + "\n" ;
navigator.clipboard.writeText(prompt);
g_navigation.openPopup(agentUrl);
 
}
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

3 REPLIES 3

Aditya_hublikar
Mega Sage

Hello @nameisnani ,

 

Can you please share screenshot . Please ensure isolate script checkbox is unchecked .

 

 

Tanushree Maiti
Kilo Patron

Hi @nameisnani ,

 

Why are your passing sys_id to the prompt, it is very internal . 

Somehow in Zurich PDI , window.open() not working ,it might be blocked by modern browser security policies.  

When it is replaced by g_navigation.openPopup , it is working .

Try it. On top of it fine tune the code as per your requirement.

function openCopilotAgent() {

 
 var agentUrl = "https://copilot.microsoft.com/";
var number = g_form.getValue('number');
var prompt =
"You are Change Quality Advisor.\n" +
"Assess this ServiceNow Change Request and return:\n" +
"1) Quality score (0-10)\n" +
"2) Missing information\n" +
"3) Risk rating\n" +
"4) Suggested improvements\n\n" +
"Record:\n" +
"Number: " + number + "\n" ;
navigator.clipboard.writeText(prompt);
g_navigation.openPopup(agentUrl);
 
}
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

@Tanushree Maiti 

 

Thank You - It got worked out