Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set Mandatory on UI action script for creating task from request related table

Are Kaveri
Tera Contributor

Hi,

 

 

I am working on Request form,

on my Request form i have a UI action called Create Task.

when i click on Create Task , The Task record gets created under Request task related list.

we have a Date field , which is mandatory to be filled before creating task.

Before Clicking on Create Task The below Requestor Task created date should be mandatory.

 

The task can be multiple for a Request. 

 

There is this below condition:

The Requestor Task Created Date must not be blank after Task creation.

if it is blank then throw below error.

 

The below is the script:

function createTaskClient() {

    if (!confirm('Do you really want to create an Task record?')) {
        return false;
    }

    /
    g_form.setMandatory('u_requestor_task_created_date', true);
     if (g_form.getValue('u_requestor_task_created_date') == '') {
        g_form.showFieldMsg('u_requestor_task_created_date', 'Requestor task Created Date is required in order to create task ', 'error');
        return false;

    } 


    // Call server side logic
    gsftSubmit(null, g_form.getFormElement(), 'create_task');
}


if (typeof window == 'undefined')
    createtask();

function createtask() {

    var grtask= new GlideRecord('sn_request_task');
    grtask.u_request_id = current.getUniqueValue();

    grtask.insert();

   
    action.setRedirectURL(grtask);

    gs.addInfoMessage("task record " + grtask.number + " is created.");
}

 

The mandatory part was failing.

 

Please help me if anyone gets any thing wrong in the script.

 

2 REPLIES 2

Runjay Patel
Giga Sage

Hi @Are Kaveri ,

 

Client script code does not work here as you are creating task via script. You can create a data policy for same and make mandatory for create.

 

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

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
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

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

@Runjay Patel  Thanks for the response.

it is client callable UI action.

Will my mandatory validation will not work here?

Can't i use this UI action for the same?

 

why Data policy why not UI policy?

 

On Data policy how can i script for error message if the field is blank?