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.

What is the alternative way to use gel() in service portal..?

Nithin12
Tera Expert

Hi Team,

Can any body let me the alternative way of gel() in service portal.

i have written this onSubmit script, which works fine in CMS,

Here i need to get value of sysparm_item_guid, how do I get with out using gel() method?

I am attaching the code:

var cat_id = gel('sysparm_item_guid').value;

var sp = new GlideRecord("sys_attachment");

  sp.addQuery("table_name", "sc_cart_item");

  sp.addQuery("table_sys_id", cat_id);

  sp.query(function(){

  if (!sp.next()) {

  g_form.addErrorMessage("Please attach the required SSL certificates/document");

  return false;

  }

  });

Any help or suggestion will help me lot  

Thanks,

Nithin.

PlatformDeveloper CommunityBlogs

10 REPLIES 10

Chuck Tomasi
Tera Patron

Hi Nitin,



The approach I would take is to use an ng-click handler and use your client script to make a REST call to determine if the attachment is available. A Scripted REST API would be very helpful here as it gives you total control over the inputs and outputs.



Scripted REST APIs


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Nithin,



You can't use any dom manipulation techniques in the service portal, but you can grab the sys_id of your catalog item with g_form.getSysId() and that should work in Service Portal. Here's a good list of what is and isn't supported in SP.



documentation/client_scripting.md at master · service-portal/documentation · GitHub



Also, instead of the client side gliderecord, you could use a script include and glideajax to determine whether or not your item has an attachment.


Thanks Brad 🙂

Nithin12
Tera Expert

Hi ctomasi, b-rad



Thanks for your reply .



I have one query.. How to make onSubmit script to stop in servcie portal ..as in service portal   we can only write asynchronous call only.


for example see below mwntioned code .. where I need to stop the submission of form if it doesn't have any attachments,But issue is in service portal we need to write only   asynchronous methods, so before getting data regarding attachments from is submitting.


function onSubmit() {


  g_form.clearMessages();


  //var cat_id = gel('sysparm_item_guid').value;


  var cart_id = g_form.getSysId();


  var sp = new GlideRecord("sys_attachment");


  sp.addQuery("table_name", "sc_cart_item");


  sp.addQuery("table_sys_id", cart_id);


  sp.query(function(sp){


  if (!sp.next()) {


  g_form.addErrorMessage("Please attach the required SSL certificates/document");


  return false;


  }


  });


}


Is there ant other way i can achieve this ?



thanks,


Nithin.