gel('sysparm_item_guid').value is not working on service portal

bryan123
Giga Contributor

Can anyone advise me of an alternative for gel('sysparm_item_guid').value code? Need to make the attachment mandatory in SERVICE PORTAL var sid = gel('sysparm_item_guid').value;     var gr_at = new GlideRecord("sys_attachment");     gr_at.addQuery("table_name", "sc_cart_item");     gr_at.addQuery("table_sys_id", sid);     gr_at.query();     var res = gr_at.next();     if (!res) {         alert("You must have an attachment to submit.");         return false;     } Appreciate the help. Thank you!

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi Bryan,



Please find this thread which is equivalently helpful making Attachment mandatory on submission of the item in both Service Portal and Scoped Application: Require attachment for catalog item in Service Portal



You need to create a new UI Script in Global Application scope and call that in your onSubmit Catalog Client Script. In your case the scripts are given below. You need to leverage your existing logic in the Catalog Client Script.



UI Script:


API Name:GlobalCatalogItemFunctions


Script:


function getSCAttachmentCount() {


  var length;


  try {


  length = angular.element("#sc_cat_item").scope().attachments.length;


  } catch(e) {


  length = -1;


  }


  return length;


}



onSubmit Catalog Client Scrip (in Global Scope):


function onSubmit() {


  try { //Works in non-portal ui


  var attachments = document.getElementById('header_attachment_list_label');


  if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {


  alert('Please attach atleast one attachment to proceed');


  return false;


  }


  }


  catch(e) { //For Service Portal


  var count = getSCAttachmentCount();


  if(count <= 0) {


  alert('Please attach atleast one attachment to proceed');


  return false;


  }


  }


}



I hope this helps. Please mark correct/helpful based on impact


View solution in original post

6 REPLIES 6

Gurpreet07
Mega Sage

Hi Bryan,



Where are you using this script, is it onSubmit script on some catalog item ?


Is this working on Service Portal?


yes onsubmit. this is working on CMS but not in service portal. do you have any alternative? Thank you for your help


Zeeshan Khan1
Kilo Guru

Hi Bryan,



I faced similar issue and found the solution here - Catalog service making Mandatory Attachment both application and SP



This might help you in making attachments mandatory,