How to open a form through UI action and pre=populate fields on form

Snehal13
Kilo Sage

So my UI action opens a modal window that has a dropdown field. whatever user choses and clicks on create button in the modal button must take him to A CREATE NEW incident form and prepopulate a field on the incident form with that selected value from popup.

 

any tips, ideas on this

 

EDIT - 

 

Here is my ask -

 

From the workspace view, click on UI action button to open a dialog window. 

The  dialog popup shows few fields (assume type and short text) and has a create button.

when I select the type and fill in the short text and click on create in the dialog window. the popup must close and a workspace view new incident form must open and the type and short text must be auto populated on the landing form. 

 

Note - this is for workspace view and not for native UI

5 REPLIES 5

DanielCordick
Mega Patron
Mega Patron

can you share your code for the modal

I do not have any code at present. trying to understand the approach from workspace UI action to proceed.

 

Here is my ask -

 

From the workspace view, click on UI action button to open a dialog window. 

The  dialog popup shows few fields (assume type and short text) and has a create button.

when I select the type and fill in the short text and click on create in the dialog window. the popup must close and a workspace view new incident form must open and the type and short text must be auto populated on the landing form. 

 

Note - this is for workspace view and not for native UI

Snehal13
Kilo Sage
function onClick(g_form) {

    var fields = [{
        type: 'textarea',
        name: 'work_notes',
        label: getMessage('Reason'),
        mandatory: true
    },
        {
            type: 'choice',
            name: 'reason_code',
            label: getMessage('Reason code'),
            value: getMessage(' -- Select -- '),
            choices: [{
                displayValue: 'Duplicate',
                value: 'duplicate'
            },
                {
                    displayValue: 'Canceled',
                    value: 'canceled'
                }
            ],
            mandatory: true
        },
        {
            type: 'reference',
            name: 'caller_id',
            label: getMessage('What is your name?'),
            mandatory: true,
            reference: 'sys_user',
            referringTable: 'incident',
            referringRecordId: g_form.getUniqueValue(),
			value: g_form.getValue('caller_id'),
			displayValue: g_form.getDisplayValue('caller_id')
        }
    ];

    g_modal.showFields({
        title: "Are you sure?",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
        // need to use the values inputted by user and open incident form in workspace and poplate fields on form with those values
    });
}

What are your field names, which field is getting populated on the incident form? You didn’t really provide YOUR code your using, 

 

the link you got that from gives you plenty of options, even shows you how to open a URL 

 

https://www.servicenow.com/community/next-experience-articles/how-to-use-ui-actions-in-workspaces/ta...