
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2023 11:06 PM
Hello,
I'm calling a script include in my catalog client script through GlideAjax, which works fine. Nevertheless, I can't find a way to return the value to the main function.
How is this possible? Preferably with an example.
Thanks in advance for your reply.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 01:24 AM
you can show field message of type error so it won't allow submitting the form.
So unless and until the user selects correct date they cannot submit it
When the validation fails show field message of type error; if validation is fine clear the message
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 12:21 AM
This is the script include:
var DWPCatalogClientUtils = Class.create();
DWPCatalogClientUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkIfDateIsGreaterThanNowInDays: function() {
var startDT = this.getParameter('sysparm_sdt');
var addDays = this.getParameter('sysparm_ad');
var amountSec = gs.dateDiff(gs.nowDateTime(), startDT, true);
var amountDays = parseInt(amountSec) / (60 * 60 * 24);
if (amountDays > parseInt(addDays)){
return true;
} else {
return false;
}
},
type: 'DWPCatalogClientUtils'
});
This is the catalog client script:
function onSubmit() {
var ecDate = g_form.getValue('ec_last_day');
var ga = new GlideAjax('DCITSMCatalogClientUtils');
ga.addParam('sysparm_name', 'getNowDateTimeDiff');
ga.addParam('sysparm_sdt', ecDate);
ga.getXML(GetDate);
function GetDate(response){
var diffSec = response.responseXML.documentElement.getAttribute("answer");
var diffDays = parseInt(diffSec) / (60 * 60 * 24);
if (diffDays > 0){
g_form.addErrorMessage('The inserted day can not be in the future!','error');
return false;
}
if (diffDays < -35) {
g_form.addErrorMessage('The inserted day can not be more than maximum 35 days ago!','error');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 12:33 AM
you just want to check these things
1) date cannot be in future
AND
2) date cannot be more than 35 days older
You can validate this using UI policy and not script required
Did you try to use that approach?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 12:56 AM
Hi Ankur,
It's true that you can show the FieldMessage through a UI policy, but this will not prevent it from submitting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 01:24 AM
you can show field message of type error so it won't allow submitting the form.
So unless and until the user selects correct date they cannot submit it
When the validation fails show field message of type error; if validation is fine clear the message
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 01:52 AM
I have configured it as follows:
It shows the message but it doesn't prevent the submit