The CreatorCon Call for Content is officially open! Get started here.

UI Action button that stays on a form and doesn't lose changes when it doesn't meet requirements

Richard78
Giga Contributor

Hello everyone,

I am hoping someone can help me with this one.

We have decided to allow our users to create duplicates from existing/old request tickets, but I have been tasked with preventing them from just creating an exact duplicate (change short desc, opened date, etc.) that part I have done. What I am hung up on is we want to not just automatically change the due date, instead we want to make the system alert if the due date is not in the future, but we want to do this in the same way as the mandatory option on a field does (popup/message on screen that says, "Date field must be a date/time in the future!" and stays on the current record and retains all changes but does not insert them).

I can create a popup, I can get the message out to screen, but I have not been able how to keep the data in the fields without updating the original record (can't do this, audit) or inserting a new record (don't want this because they could just leave the ticket and it would just run through the workflow with a date in the past).

Hoping someone has done this before, thank you in advance for your assistance.

below is my   script:

//Initialize
var cUser = gs.getUser();
var myTime = new GlideDateTime();
var threeDays = new GlideDateTime();

//set the date of threeDays so that it is +2 days from now.
threeDays.setValue(gs.daysAgo(-2));

//modify the original description and place in a variable
var sDesc = current.short_description;
var pos = sDesc.indexOf('request');
pos = pos+7;
sDesc = (sDesc.substring(0,pos))+" - copied from request: "+current.number;

//Set all the values for the new record.
current.setValue('opened_at', myTime);
current.setValue('assigned_to', "");
current.setValue('number', "");
current.setValue('state', "Open");
current.setValue('requested_for', cUser.getID());
current.setValue('location', cUser.getLocation());
current.setValue('opened_by', cUser.getID());
current.setValue('short_description', sDesc);

//Check state of the due-date, if current or newer set value to true
var ddResult = false;
if(current.due_date >= myTime){
ddResult = true;
}

//if date is good insert new record and display message
if(ddResult){
answer = current.insert();
gs.addInfoMessage("Request " + current.number + " created\nddResult: "+ddResult);
}
//if date is not good display message and stay on current record.
else{
gs.addInfoMessage("Due date cannot be older than current date/time!");
action.setRedirectURL(current);
action.setReturnURL(current);
}

1 ACCEPTED SOLUTION

iDestroy
Kilo Expert

Hi Richard,



Have you tried using current.setAbortAction('true'); in your else statement? That should prevent any submission to the database and kick the user back to where they were (even without your redirects).



Also, I might have missed it - but your not using your GDT var of "threeDays" anywhere


View solution in original post

3 REPLIES 3

iDestroy
Kilo Expert

Hi Richard,



Have you tried using current.setAbortAction('true'); in your else statement? That should prevent any submission to the database and kick the user back to where they were (even without your redirects).



Also, I might have missed it - but your not using your GDT var of "threeDays" anywhere


Thanks Michael,


That is exactly what I needed.


The threeDays was being used before to set the due date if it wasn't set in the future, I need to delete it now.


Thanks again.


No problem Richard - feel free to mark my answer as the correct solution just so people know this one's sorted