Trying to save form with onLoad client script

Kyle Wiley
Mega Expert

I have having some trouble here... I am fairly new to scripting and I am trying to save the form on load because they script is bringing new reference fields into the form for the people working the task but without saving it at least once when you open the task, it asks you to save every time before navtigating away from the page.   Everything in the script is working except the Save of the form.   What am I missing?

function onCondition() {

  var item = $("current_item");

  var guide = $("sysparm_guide");

  if (item != null && guide != null && item.value == guide.value)

  return;

  g_form.setMandatory('emp_start_date',true);

  g_form.setMandatory('employee_name',true);

  g_form.setDisplay('employee_number',false);

  g_form.setDisplay('department',false);

  g_form.setDisplay('job_class',false);

  g_form.setDisplay('ad_id',false);

  g_form.setDisplay('job_code',false);

  g_form.save();

}

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're on a catalog task form, you can use the following line to save the form.



gsftSubmit(gel('sysverb_update_and_stay'));


View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're on a catalog task form, you can use the following line to save the form.



gsftSubmit(gel('sysverb_update_and_stay'));


Thanks, that worked!