onSubmit Catalog Client script not working in Service portal

Bargavi
Mega Expert

Hi,

There is a field "App Code" in one of the catalog items which has a validation to check if the user is entering already existing app code, in case he is entering the existing one it should alert   "Requested app code already exists choose a different one".

I am using the below script:

var ui_app_code = g_form.getValue('u_requested_app_code');
var gr = new GlideRecord('cmdb_ci_appl');
gr.addQuery('u_application_code', ui_app_code);      
gr.query();

while(gr.next())
{

alert (" Requested App code already exists. Please choose a different one...");
return false;
}
}

If I am trying to submit the catalog item using the existing app code from an ESS page I have an alert and the form does not get submitted but the same is not working in service portal. can some one help me on what modifications has to be done to the code to make it work in service portal.

Thanks,

Bargavi

1 ACCEPTED SOLUTION

Bargavi
Mega Expert

was able to resolve it using thread Catalog Client Script asyncrhonous query to stop submission onSubmit.



Thanks for replying



-Bargavi


View solution in original post

12 REPLIES 12

LaurentChicoine
Tera Guru

From my knowledge, alert does not work on service portal.



You should instead use g_form.addErroMessage or g_form.addInfoMessage


alert() still works in SP for me. I think I remember seeing somewhere that if you're using client side gliderecord in SP you have to use a callback in the query(callback) function. Can't remember where I saw that, and if you're doing it on submit making it async isn't going to help you.


Usually using callback function will solve the problem. But in your use case, you are using onSubmit client script and you want to abort the submission based on your evaluation. CallBack will not work in this case. Did you try using GlideAjax and getXMLWait()?


Bargavi
Mega Expert

was able to resolve it using thread Catalog Client Script asyncrhonous query to stop submission onSubmit.



Thanks for replying



-Bargavi


If the issue is resolved,please mark this thread as answered.



Thanks in advance !