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.

GlideModalForm setSysID() "Record not found" when rendering

joseph_m52
Tera Expert

Spent an afternoon dealing with record not found errors when setting a valid sys_id. I wanted to put some exposer on it because it seems there is a limited number of posts on this forum in regards to GlideModalForm. The overall issue was that a query cannot be passed when trying to pull up an existing record with .setSysID().

 

For example I was passing both a query and a sys id:

var id = '<sys_id>';
var query = 'state=' + g_form.getValue('state');
query += '^route=' + g_form.getValue('route');
query += '^work_start=' + g_form.getValue('work_start');
	
  var gModalForm = new GlideModalForm('TITLE', 'TABLE');
  gModalForm.setSysID(id);
  gModalForm.setPreference('sysparm_query',query);
  gModalForm.addParm('sysparm_view', "VIEW");

  gModalForm.render(); // will render modal with No record found error

 

My solution to pull up an existing record for updating:

 

  var id = <sys_id>;
  var gModalForm = new GlideModalForm('TITLE', 'TABLE');
  gModalForm.setSysID(id);
  gModalForm.addParm('sysparm_view', "VIEW");

  gModalForm.render(); // renders correct record in modal

 

To my understanding, passing a query would be used to create new record/form with pre-populated values.

 

Hope this helps others dealing with modal forms!

 

1 ACCEPTED SOLUTION

joseph_m52
Tera Expert

 

My solution to pull up an existing record for updating:

 

  var id = <sys_id>;
  var gModalForm = new GlideModalForm('TITLE', 'TABLE');
  gModalForm.setSysID(id);
  gModalForm.addParm('sysparm_view', "VIEW");

  gModalForm.render(); // renders correct record in modal

 

To my understanding, passing a query would be used to create new record/form with pre-populated values.

View solution in original post

1 REPLY 1

joseph_m52
Tera Expert

 

My solution to pull up an existing record for updating:

 

  var id = <sys_id>;
  var gModalForm = new GlideModalForm('TITLE', 'TABLE');
  gModalForm.setSysID(id);
  gModalForm.addParm('sysparm_view', "VIEW");

  gModalForm.render(); // renders correct record in modal

 

To my understanding, passing a query would be used to create new record/form with pre-populated values.