Create a business rule / onsubmit script to restrict the form from updating/submitting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 08:00 PM
Hi Team,
I am using an Onchange client script on outage form to show error message on two fields. But the issue is that i am able to save or submit the form despite the error. Can we create a business rule / onsubmit client script to restrict the form from updating/submitting if there are field error message .Could you please let me know what alternate ways we can try to achieve this.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 08:57 PM - edited 01-05-2023 11:46 PM
Hi
The requirement is to validate begin and end fields to be with in the change window of change mentioned in task_number on Outage form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 09:10 PM
So you want to abort if user tries to select begin date after end date ?
Regards,
Shyamkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 09:17 PM
Hi @Uttam Sai
Use the onSubmit() client script and restrict the record submission using return false. Basically, return false will stop the record from inserting.
Please mark the answer as helpful if it helped you accordingly!
Thanks,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2023 10:09 PM
Hi @Hari Prasath ,
I need a business rule which doesn't allow record to save or submit if the outage begin and end date are not within change window. Could you please help me with that. I don't want to change the onchange script , as i want the error messages to appear Onchnage when user change the value on the field. Please let me know if you need further inputs.
Thank you 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2023 07:35 PM
Hi @Hari Prasath ,
The requirement is to validate begin and end dates such that begin and end date/time should not be before change start date/time or after the change end date/time. I have been using below Client Script and Script Include. Could you please suggest equivalent Business rule , which restrict form from submitting and updating
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var num = g_form.getReference('task_number',func);
function func(num)
{
if(num.number.toString().indexOf('CHG')>-1)
{
var ga = new GlideAjax('ChangeRequestCheckBeginDate'); //client callable script include
ga.addParam('sysparm_name', 'checkStartofChange'); //function name on the script include
ga.addParam('outageStartDate', newValue); // the begin date selected by the user
ga.addParam('changeId', g_form.getValue('task_number')); //changeID - to query and compare with the change start date.
ga.getXML(verifystartdate);
}
}
function verifystartdate(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'false'){
alert('Outage Begin date should be within the Change Planned Window');
//g_form.addErrorMessage(getMessage("Outage begin date cannot be before change start date"));
g_form.showFieldMsg('begin','Outage Begin date should be within the Change Planned Window','error');
//g_form.clearValue('begin'); //to clear out the value selected by the user
}
}
}
Script Include:
var ChangeRequestCheckBeginDate = Class.create();
ChangeRequestCheckBeginDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkStartofChange: function(){
var begin = new GlideDateTime();
begin.setDisplayValue(this.getParameter('outageStartDate'));
begin = begin.getNumericValue() - begin.getTZOffset();
var changeId = this.getParameter('changeId'); //the changeID
var changeGR = new GlideRecord('change_request');
changeGR.get(changeId);
var ChangeStart = new GlideDateTime();
ChangeStart.setDisplayValueInternal(changeGR.start_date);
ChangeStart = ChangeStart.getNumericValue();
var ChangeEnd = new GlideDateTime();
ChangeEnd.setDisplayValueInternal(changeGR.end_date);
ChangeEnd = ChangeEnd.getNumericValue();
if(begin < ChangeStart || begin > ChangeEnd){
return false;
}
else{
return true;
}
},
type: 'ChangeRequestCheckBeginDate'
});