gel('sysparm_item_guid').value is not working with Istanbul version

vai
Kilo Contributor

Hi All,

I am trying to validate the attachment type on submit of request, noticed that   gel function is not supported with Istanbul version.

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

   

    var gr = new GlideRecord("sys_attachment");

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

    gr.addQuery("table_sys_id", cat_id);

    gr.query();

    while (gr.next()) {

      if(gr.getValue("content_type") != 'application/text'){//meaning if you find a file with xls extension

              //do something

       

              return false;

      }

what is the alternative for gel('sysparm_item_guid').value ?

1 ACCEPTED SOLUTION

Hi Vineeth,



g_form.getValue('sysparm_item_guid') should work correctly in scoped app. But the problem is you cannot use GlideRecord   in client side in scoped app which leads to using GlideAjax in onSubmit client script. It also has one issue that is getXMLWait() doesn't work in scoped app.


So this post gives you workaround on the same.


But you can try one more option



Create Catalog client script in global scope for that catalog item and use following script then it will stop form submission. I have tried the same way and it worked for me for catalog item present in scoped app



Script:


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


var gr = new GlideRecord("sys_attachment");


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


gr.addQuery("table_sys_id", cat_id);


gr.query();


if (!gr.next()) {


alert("Please add attachment");


return false;


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vineeth,



Following link provides an approach:


How to fix onSubmit data validation once and for all in Scoped Applications



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,



g_form.getValue('sysparm_item_guid') is giving different values when used in global scope and in my application scope... in global scope it is giving the table_sys_id of the record in sys_attachment table, in my application scope it giving some id not sure what is that id..


Hi Vineeth,



g_form.getValue('sysparm_item_guid') should work correctly in scoped app. But the problem is you cannot use GlideRecord   in client side in scoped app which leads to using GlideAjax in onSubmit client script. It also has one issue that is getXMLWait() doesn't work in scoped app.


So this post gives you workaround on the same.


But you can try one more option



Create Catalog client script in global scope for that catalog item and use following script then it will stop form submission. I have tried the same way and it worked for me for catalog item present in scoped app



Script:


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


var gr = new GlideRecord("sys_attachment");


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


gr.addQuery("table_sys_id", cat_id);


gr.query();


if (!gr.next()) {


alert("Please add attachment");


return false;


}



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Vineeth,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Vineeth,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader