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

Ahmed Hmeid1
Kilo Guru

Try replacing gel('sysparm_item_guid').value with g_form.getUniqueValue()



scripts using gel, document, location, window, $, $j, angular are all considered DOM manipulation techniques and are not available for use in the Service Portal



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