Perform server-side UI actions ignoring required fields

bonsai
Mega Sage

I would like to execute the UI action "Copy Record" with the required fields left blank.

It has the same specifications as copying incident management records.

Currently, if a required field is left blank, a message prompting for input will be displayed.

I want to perform a record copy ignoring required fields.

4 REPLIES 4

Muhammad Hamza
Kilo Sage

Hey @bonsai,

You can try this process.

Create a Client UI Action.

MuhammadHamza_0-1704766993312.png

 

function copyIncident() {
// make fields un-mandatory on the form
    g_form.setMandatory("caller_id", false);
    g_form.setMandatory("short_description", false);

    var gax = new GlideAjax("CopyIncident");
    gax.addParam("sysparm_name", "copyIncidentFunc");

    gax.getXML(callbackFunction);

    function callbackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.addInfoMessage("Incident Created: "+answer);
    }
}

 

Make all of your fields un-mandatory and then call a Client Callable Script Include.

MuhammadHamza_1-1704767127112.png

 

var CopyIncident = Class.create();
CopyIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    copyIncidentFunc: function() {
        
        var gr = new GlideRecord("incident");
        gr.setWorkflow(false);
        gr.initialize();
        gr.insert();
		return ""+gr.number;

    },

    type: 'CopyIncident'
});

 

In this way, you can create incidents without filling the Required/Mandatory Fields.

Incident used to create a new one:

MuhammadHamza_2-1704767233294.png

New Incident Created:

 

MuhammadHamza_3-1704767271315.png

Kindly appreciate the efforts of community contributors by marking appropriate response as the correct solution and helpful, this may help other community users to follow the right solution in the future.

Thanks,

Hamza

 

Is it possible to copy fields?

Also, when copying, is there an efficient way to copy all fields of a record?

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

this is for a custom table and your UI action is a custom one?

If this is for your custom table and custom UI action is created then you can add that logic as per your requirement

Please share your UI action script and what changes you have done so far

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

@bonsai 

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