- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2012 10:00 AM
Hi everyone, wanted to ask a question about something that recently happened. before the creation of a record, I have a few before business rules that run to make sure the information supplied is correct. For example, a date field. If the user entered date does not fall on a sunday, submission of the record is cancelled and they are prompted to change that date. It works fine, but only if one mistake is made. Example....I user tries to submit with incorrect information, an error is thrown and they are prompted to change the value. Now lets say they enter another incorrect value, the error is thrown again. They then change to a correct value and submit the record. A "Record not found" error is appearing, but if I look at the list, it was inserted. Can anyone explain why this is happening? Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 06:54 AM
try something like this:
function onSubmit()
{
var ajax = new GlideAjax('TimeCardDateAjax');
ajax.addParam('sysparm_name','TimeCardDate');
ajax.addParam('sysparm_week_starts_on', g_form.getValue('week_starts_on'));
ajax.getXMLWait();
var val = ajax.getAnswer();
g_form.addInfoMessage(val); //testing to see what parameter is coming from script include
if(val == '1')
{
return true;
}
else
{
g_form.addErrorMessage("Some Error in here")
return false;
}
}
Then in the Script Include:
var valid = 0;
var weekStarts = this.getParameter('sysparm_week_starts_on');
var weekStartsObj = new GlideDateTime(weekStarts); //may need to look up correct syntax in the wiki for new GlideDateTime
if(weekStartsObj.getGlideObject().getDayOfWeekUTC() == '7')
{
valid = 1;
]
return valid;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2012 07:15 PM
It sounds like you're seeing a chicken/egg thing showing up. It sounds like somehow you're saving the record, but then erroring out on a downstream data check. I would consider doing some of these checks using AJAX or just Client Scripts as that will give you better performance(if you can do it Client side) and you will not be messing with the DB until you're absolutely ready.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 06:47 AM
Thanks for the response Chris. I like the idea of using an AJAX call. Although, I am having trouble figuring how I could perform that validation in the script include and pass it over. How could I get the contents of my 'week_starts_on' field? In my current business rule I am using
current.week_starts_on.getGlideObject().getDayOfWeekUTC()
All I plan on doing is something like the following in the script include...
var valid = 0;
if(current.week_starts_on.getGlideObject().getDayOfWeekUTC() == '7')
{
valid = 1;
]
return valid;
And a onSubmit() client script like the following...
function onSubmit()
{
var ajax = new GlideAjax('TimeCardDateAjax');
ajax.addParam('sysparm_name','TimeCardDate');
ajax.getXMLWait();
var val = ajax.getAnswer();
g_form.addInfoMessage(val); //testing to see what parameter is coming from script include
if(val == '1')
{
return true;
}
else
{
g_form.addErrorMessage("Some Error in here")
return false;
}
}
I am having trouble figuring out how to intially get the contents of the week_starts_field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 06:54 AM
try something like this:
function onSubmit()
{
var ajax = new GlideAjax('TimeCardDateAjax');
ajax.addParam('sysparm_name','TimeCardDate');
ajax.addParam('sysparm_week_starts_on', g_form.getValue('week_starts_on'));
ajax.getXMLWait();
var val = ajax.getAnswer();
g_form.addInfoMessage(val); //testing to see what parameter is coming from script include
if(val == '1')
{
return true;
}
else
{
g_form.addErrorMessage("Some Error in here")
return false;
}
}
Then in the Script Include:
var valid = 0;
var weekStarts = this.getParameter('sysparm_week_starts_on');
var weekStartsObj = new GlideDateTime(weekStarts); //may need to look up correct syntax in the wiki for new GlideDateTime
if(weekStartsObj.getGlideObject().getDayOfWeekUTC() == '7')
{
valid = 1;
]
return valid;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2012 07:52 AM
Ah ok I see. I think there is an issue with the if statement
if(weekStartsObj.getGlideObject().getDayOfWeekUTC() == '7')
The function is passing a 0 even when a Sunday is chosen. For testing purposes I replaced that if statement with if(1>0) and it returned the 1 in that case and allowed submission. Thats a little confusing since I had a business rule that had the same if statement and it worked.