'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

Haseeb-Ahmed
ServiceNow Employee
ServiceNow Employee

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

Chandrima Mukh2
Tera Contributor

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.

ChandrimaMukh2_0-1708317670523.png

Any help will be appreciated.

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.

Service_RNow
Mega Sage

Hi @Chandrima Mukh2 

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!