Can we Make users to select the choice field (State Field ) in POP up message?

devservicenow k
Tera Contributor

My Requirement is To show a POP up message with the State choice Field, From that the user should choose the State fields by UI action through Testing Buttons.

On clicking the Testing Button, POP up Message should get displayed with State field , from that the user should select the choice, but other choices are not getting displayed , how tosolve this?

 

function onClick(g_form) {
    g_modal.showFields({
        title: "Enter your reason",
        fields: [{
            type: 'reference',
            name: 'state',
            label: getMessage('Reason'),
            mandatory: true,
            reference:'state',
            referringTable: 'incident',
            referringRecordId: g_form.getUniqueValue(),
            value: g_form.getValue('state'),
            displayValue: g_form.getDisplayValue('state'),
        }],
        size: 'lg'
    }).then(function(fieldValues) {
        g_form.setValue('state', fieldValues.updatedFields[0].value);
        g_form.save();
    });
}

what to change in script?

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your type is reference then how it will show choices

you should be using type as choice

Refer my blog and enhance the logic

Populating dynamic choices in workspace form pane for choice field type

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@devservicenow k 

your script will look like this

Enhance as per your requirement

function onClick(g_form) {

	var arr = [];
	var obj = {};
	obj["value"] = "1";
	obj["displayValue"] = "New";
	arr.push(obj);

	var obj1 = {};
	obj1["value"] = "2";
	obj1["displayValue"] = "Work in progress";
	arr.push(obj1);

	g_modal.showFields({
		title: "Enter your reason",
		fields: [{
			type: 'choice',
			name: 'state',
			label: getMessage('Reason'),
			mandatory: true,
			choices: arr
		}],
		size: 'lg'
	}).then(function(fieldValues) {
		g_form.setValue('state', fieldValues.updatedFields[0].value);
		g_form.save();
	});
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

yes bro its working. But , i need When user is Selecting New , automatically another task should be created how to do this?

Is it possible to create a task from this pop up itself, then from where i need to change the script, can you please provide me with script