- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2016 07:33 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2016 10:01 AM
was able to resolve it using thread Catalog Client Script asyncrhonous query to stop submission onSubmit.
Thanks for replying
-Bargavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2017 10:19 AM
Could you provide the solution you put in place? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2017 09:45 AM
Yes sure..
Below is the script:
function onSubmit() {
//If ServicePortal
if (!window) {
if (g_scratchpad.isFormValid) {
return true;
}
g_form.hideAllFieldMsgs('error');
var actionName = g_form.getActionName();
//Application code contain letters numbers and dashes only
var app_code = g_form.getValue('field_name');
//Check if entered Code already exists
var ac = new GlideRecord(cmdb_ci_application');
ac.addQuery('u_application_code', app_code);
//Callback function to control stop submit asynchronously
ac.query(function() {
while (ac.next()) {
alert('Requested Application Code already exists, Please choose a different one..!' );
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
});
return false;
}
}
/* if CMS
function onSubmit()
{
//var ui_app_code = g_form.getValue('u_requested_app_code');
//alert ('Requested App Code:, ui_app_code' );
var gr = new GlideRecord('cmdb_ci_appl');
gr.addQuery('u_application_code', g_form.getValue('u_requested_app_code'));
gr.query();
if (gr.hasNext())
{
alert("Requested App code already exists. Please choose a different one...");
return false;
}
}
*/
Please let me know whether the solution was helpful or not.
-Bargavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2017 10:34 AM
Hello Bhargavi,
Can I know what exactly these two lines are doing.
- g_scratchpad.isFormValid = true;
- g_form.submit(actionName);
Because i have used same code with out using g_scratchpad.isFormValid and g_form.submit(actionName), how these two lines are stoping the asynchronous function.I got confused can you brief me..?
Thanks,
Nithin.