The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Set default Value on choice field type Task_sla

Community Alums
Not applicable

Hello folks, 

 

I have a condition to set a default value of 'Unsubmitted' on a field that's visible only in list view.

I've tried to use this client script onLoad, unsuccessfully failed to update at least one record: 

function onLoad() {
    // indicate the concern field
    var fieldName = 'u_uncheck_status';

    // specify the default value
    var defaultValue = g_form.getValue(fieldName);
    //alert('B '+defaultValue);

    //set this defaulkt value for the choice list filed in task_sla table
    g_form.setValue(fieldName, defaultValue);
 
 

The standard "Defualt Value" works but the value is not visible unless double click on the field.
So far, a backgroupd script work fine by retrieveing a sys_id of a record for testing purposes.

 

Here's the backgroup script:


    // Indicate the concern field
    var fieldName = 'u_uncheck_status';

    // Specify the default value
    var defaultValue = 'Unsubmitted';

    // Create a GlideRecord to query a specific record.
    var taskSla = new GlideRecord('task_sla');
    //taskSla.addQuery("sys_id", "48d780dddb03995010df297cd39619ba");
    taskSla.addEncodedQuery('active=true');
    taskSla.setLimit(20);
    taskSla.query();

    // Verify if the record is found
    if (taskSla.next()) {
        // Set the default value for the choice list field in the record
        taskSla.u_uncheck_status = defaultValue;
        taskSla.autoSysFields(false);
        taskSla.update();
    }

   
Is there a way setting up a default value for a  choice field type that's visible on list view ? 
 
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello, 

I've resolved my issue, I had to enter a default value before pressing save to create a field.
That way, it updates all the records on the table with the predefined default value and then create choices.

View solution in original post

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @Community Alums 

 

Instead of onLoad client script, Try creating a Before - Insert business rule with the following script.

 

(function executeRule(current, previous /*null when async*/ ) {

    var current_value = current.u_uncheck_status;
    if (gs.nil(current_value)) {
        var defaultValue = 'Unsubmitted';
        current.u_uncheck_status = defaultValue;
    }

})(current, previous);

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

Community Alums
Not applicable

Thanks @AnveshKumar M,

A Business Rule at Before - Insert will not work, it will require an action, but I gave it a try anyway, it didn't work as expected.


Community Alums
Not applicable

Hello, 

I've resolved my issue, I had to enter a default value before pressing save to create a field.
That way, it updates all the records on the table with the predefined default value and then create choices.