'g_form' not working in Action Assignment in ServiceNow Workspace

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2024 09:26 PM
I am creating an Action Assignment "Update Document Category" for attachment in Incident Table as a part of Service Operations Workspace.
The Action Assignment is of type "Client Script" and the script is as below
function onClick(g_form) {
var ga = new GlideAjax('GetMyChoices');
ga.addParam('sysparm_name', 'getFieldChoices');
ga.getXMLAnswer(function(answer1) {
var answer = JSON.parse(answer1);
fields.push({
type: 'choice',
name: 'u_category',
label: getMessage('Document Category'),
choices: answer.choices,
mandatory: true
});
g_modal.showFields({
title: "Upload Document Category",
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_form.setDisplayValue("short_description", fieldValues.updatedFields[0].value);
});
});
}
I am seeing that inside the script g_form object is undefined, and functions like setValue, addInfoMessage, etc not working. Can anyone advise me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2024 01:22 AM
Hi @Chandrima Mukh2 ,
I see the use case opens a modal on click of attachment declarative action, and from modal interaction want to update fields on form/record.
For this use case, explore UXF client-type declarative action.
you may refer to https://www.servicenow.com/community/developer-blog/declarative-actions-in-servicenow-the-complete-g... to understand how UXF client-type action works.
As the implementation would be custom, so may not be able to provide complete implementation here, though this document should be enough to guide you.
Please accept the solution or give a thumbs up if it answers your query.
Thanks,
Haseeb Ahmed

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2024 08:44 PM
Hi @Haseeb-Ahmed ,
Thanks for sharing the link, it has insightful information. Excellent post.
However I am not able to access the Action Model Fields using client script.
Any help will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 02:27 AM
Action modal fields will be accessible via UXF client action payload and client condition on DA (you may search for the same in the attached article)
Though g_form API should be accessible in the client script.
For your use case UXF client action will fit, please explore more in that direction.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2024 10:28 PM
Please try with JSON return the server side data (In Script Include) like below
return JSON.stringify(data);
you need to do like below
var arr = JSON.parse(ga.getAnswer1());
Please mark reply as Helpful/Correct, if applicable. Thanks!