i want to make assigned to mandatory

PRAGHATIESH S
Tera Expert

Hi,

 

There is OOB Ui action for interaction table "Close".  when we click on that close button it needs to make "assigned to" mandatory.

can anyone let me know, how can i make changes on here.

PRAGHATIESHS_0-1735554766866.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@PRAGHATIESH S 

Please remember this is an OOB UI Action and if you update it then during upgrade it will be skipped

is it for native or workspace that you want to make it mandatory?

Client Script:

function closeInteraction() {

	if(g_form.getValue('assigned_to') == ''){
		g_form.addInfoMessage('Please fill assigned to');
		g_form.setMandatory('assigned_to', true);
		return;
	}

	var dialog = new GlideModal("close_confirmation");
	var msg = getMessage('Confirmation');
	dialog.setTitle(msg);
	dialog.setPreference("sys_id", g_form.getUniqueValue());
	dialog.render();
}

Workspace client script:

function onClick(g_form) {

    getMessage("Are you sure you want to close this interaction?", function(msg) {

        if (g_form.getValue('assigned_to') == '') {
            g_form.addInfoMessage('Please fill assigned to');
            g_form.setMandatory('assigned_to', true);
            return;
        }

        g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
            if (confirmed) {
                g_form.setValue('state', 'closed_complete');
                g_form.save();
            }
        });
    });

    return false;
}

AnkurBawiskar_0-1735558823226.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

Hi @PRAGHATIESH S 

 

If I am not wrong, it looks like some changes have been done in UI Action, the OOTB code is different. Please make changes and then add your condition

 

AGLearnNGrow_0-1735557768783.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@PRAGHATIESH S 

Please remember this is an OOB UI Action and if you update it then during upgrade it will be skipped

is it for native or workspace that you want to make it mandatory?

Client Script:

function closeInteraction() {

	if(g_form.getValue('assigned_to') == ''){
		g_form.addInfoMessage('Please fill assigned to');
		g_form.setMandatory('assigned_to', true);
		return;
	}

	var dialog = new GlideModal("close_confirmation");
	var msg = getMessage('Confirmation');
	dialog.setTitle(msg);
	dialog.setPreference("sys_id", g_form.getUniqueValue());
	dialog.render();
}

Workspace client script:

function onClick(g_form) {

    getMessage("Are you sure you want to close this interaction?", function(msg) {

        if (g_form.getValue('assigned_to') == '') {
            g_form.addInfoMessage('Please fill assigned to');
            g_form.setMandatory('assigned_to', true);
            return;
        }

        g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
            if (confirmed) {
                g_form.setValue('state', 'closed_complete');
                g_form.save();
            }
        });
    });

    return false;
}

AnkurBawiskar_0-1735558823226.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@PRAGHATIESH S 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Runjay Patel
Giga Sage

Hi @PRAGHATIESH S ,

 

Use below code in workspace client script.

getMessage("Are you sure you want to close this interaction?", function (msg) {
    g_modal.confirm(getMessage("Confirmation"), msg, function (confirmed) {
        if (confirmed) {
            // Check if "Assigned to" has a value
            if (!g_form.getValue('assigned_to')) {
                g_form.addErrorMessage("The 'Assigned to' field is mandatory. Please provide a value.");
                g_form.showFieldMsg('assigned_to', "This field is mandatory.", 'error');
                return false;
            }
            
            // Proceed to close the interaction
            g_form.setValue('state', 'closed_complete');
            g_form.save();
        }
    });
});

return false;

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Omkar Mone
Mega Sage

You need to create a data policy here. Do try and let me know