'g_form' not working in Action Assignment in ServiceNow Workspace

Chandrima Mukh2
Tera Contributor

I am creating an Action Assignment "Update Document Category" for attachment in Incident Table as a part of Service Operations Workspace.

ChandrimaMukh2_0-1708147237598.png

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.

6 REPLIES 6

Tai Vu
Kilo Patron
Kilo Patron

Hi @Chandrima Mukh2 

It appears that there's no setDisplayValue within GlideForm API at this line below.

g_form.setDisplayValue("short_description", fieldValues.updatedFields[0].value);

 

Cheers,

Tai Vu

Daxin
Tera Expert

Hi, 

I think the issue is here 

 

function onClick(g_form) {

 

Onclick doesn't expect any argument. Try with just  "function onClick()" .