- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2022 11:49 PM
Hi all,
I am trying to glide record the catalog item variable values but unable to glide. Here is the script i have written in script include:
var start = this.getParameter('sysparm_start');
var end = this.getParameter('sysparm_end');
var returnObj = {};
returnObj.isValid = true;
var reqItem = new GlideRecord('sc_req_item');
reqItem.query();
while(reqItem.next() && (reqItem.variables.demo_starts >= start && reqItem.variables.demo_starts < start)) { // If statement is not getting triggered even the condition evaluates to true
returnObj.isValid = false;
gs.addErrorMessage('Conflict.........');
gs.setAbortAction(true);
}
return JSON.stringify(returnObj);
Is this the correct format to fetch the variable values or is there any other way to do it?
Thanks,
Yesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 12:29 AM
Hi,
Then do this
1) send 1 more parameter to Ajax i.e. catalog item sysId
2) update script include as this
var start = this.getParameter('sysparm_start');
var end = this.getParameter('sysparm_end');
var sysId = this.getParameter('sysparm_catalogItemSysId');
var isValid = 'true';
var reqItem = new GlideRecord('sc_req_item');
reqItem.addQuery('cat_item', sysId);
reqItem.query();
while(reqItem.next()){
if(new GlideDateTime(reqItem.variables.demo_starts).getNumericValue() >= new GlideDateTime(start).getNumericValue() && new GlideDateTime(reqItem.variables.demo_starts).getNumericValue() < new GlideDateTime(end).getNumericValue()) {
isValid = 'false';
break;
}
}
return isValid;
In client script check the isValid flag
if(isValid == 'false'){
alert('Invalid dates');
// show error near those 2 variables so that form is not submitted
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2022 11:51 PM
Hi,
Can you explain what's your requirement?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 12:00 AM
Hi
My exact requirement is I have a catalog item named Demo Request, in that i have two variables called demo start time and end time. If there is another demo request submitted with the same start time selected now or the current selected start time is in between the start time and end time that was already requested by someone, then it should not allow you to submit the current demo request.
I hope you got my requirement.
Thanks,
Yesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 12:29 AM
Hi,
Then do this
1) send 1 more parameter to Ajax i.e. catalog item sysId
2) update script include as this
var start = this.getParameter('sysparm_start');
var end = this.getParameter('sysparm_end');
var sysId = this.getParameter('sysparm_catalogItemSysId');
var isValid = 'true';
var reqItem = new GlideRecord('sc_req_item');
reqItem.addQuery('cat_item', sysId);
reqItem.query();
while(reqItem.next()){
if(new GlideDateTime(reqItem.variables.demo_starts).getNumericValue() >= new GlideDateTime(start).getNumericValue() && new GlideDateTime(reqItem.variables.demo_starts).getNumericValue() < new GlideDateTime(end).getNumericValue()) {
isValid = 'false';
break;
}
}
return isValid;
In client script check the isValid flag
if(isValid == 'false'){
alert('Invalid dates');
// show error near those 2 variables so that form is not submitted
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 01:41 AM
Hi,
Thanks. It worked.