Onload Client Script to make Variable mandatory is getting clear on load of form

ukti
Tera Contributor

Hi All,

 

I have written Onload Client Script to make variable "is_this_it_sponsored" within the variable editor mandatory based on catalog task short description. When I enter the value and close the task. Then after the form reloads the value is getting clear and again showing mandatory .Can you all please help me with this.

 

ukti_0-1727631541008.png

 

 

 

function onLoad() {

    if (g_form.getValue('short_description') == 'Review request details') {

        g_form.setMandatory('variables.is_this_it_sponsored', true);

    } else if (g_form.getValue('short_description') == 'Conduct Technical evaluation' ||
        g_form.getValue('short_description') == 'Review integration request & schedule discovery meeting') {

        g_form.setMandatory('variables.operational_impact', true);

        g_form.setMandatory('variables.is_this_it_sponsored', false);
        g_form.setDisplay('variables.is_this_it_sponsored', false);


    } else if (g_form.getValue('short_description') == 'Conduct AI review' || g_form.getValue('short_description') == 'Conduct Cloud review' ||
        g_form.getValue('short_description') == 'Conduct Infosec review') {

        g_form.setDisplay('variables.operational_impact', true);
        g_form.setReadOnly('variables.operational_impact', true);

    } else {

        g_form.setMandatory('variables.operational_impact', false);
        g_form.setDisplay('variables.operational_impact', false);
   
        g_form.setMandatory('variables.is_this_it_sponsored', false);
        g_form.setDisplay('variables.is_this_it_sponsored', false);
    }


}

 

 

12 REPLIES 12

ukti
Tera Contributor

Hi @Siddhesh Jadhav : How we can save the value using GlideRecord. Can you help me with some script example?

@ukti 
 Here it is:

var gr = new GlideRecord('incident');

gr.initialize();

gr.short_description = 'This is a test incident';
gr.category = 'network';
gr.priority = 2;
gr.assigned_to = 'YOUR_USER_ID';

var sys_id = gr.insert();

gs.info('New Incident Created with sys_id: ' + sys_id);

 

@ukti no! wrong!! abort!!! AI fail.  You do not want or need a GlideRecord in your scenario, especially one like this.