How to hide a button once it is submitted

Abdul333
Tera Contributor

Hello All,

 

I created a button in incident form called "Send Reminder".

Once it is submitted need to hide the button, generally while refreshing it is hiding.

it is needs automatically refresh the form once submitted.

 

function onClick(g_form) {
    var answer = confirm('Should reminder be sent to all agents of currently assigned group?');
    if (answer == false) {
        return false;
    }
    //gsftSubmit(null, g_form.getFormElement(), 'send_reminder');
g_form.submit(g_form.getFormElement());
//alert('Submit button testing');
}
if (typeof window == 'undefined')
    runServerCode();
 
function runServerCode() {
    gs.eventQueue('incident.sendreminder', current, 'current.assignment_group');
//alert('testing incident assignment group');
    action.setRedirectURL(current);
    gs.addInfoMessage("Reminder sent successfully");
//alert('checking add info message');
}
 
please check my code and correct me so that it will get auto hidden once submitted.
 
 

please help me on this.

 

@SANDEEP28 @Ankur Bawiskar 

 

Thanks,

Abdul

 

13 REPLIES 13

@SANDEEP28 as you know i already created script include for that to show in Business Hours.

I create custom field u_email_sent in incident table with type True/False.

Do i need to add the given script in UI action itself?

current.u_email_sent = true;

current.update();

action.setRedirectUrl(current);

 

Please correct me if i'm wrong.

 

 

Thanks,

Abdul

SANDEEP28
Mega Sage

@Abdul333 Yes you need to add script in UI action and also append the "current.u_email_sent == false" in the condition field of UI action.

@SANDEEP28 it is working, but the thing is we need to show the button again after 2hours.

Could you please help me on this, so that after sending an email the button will be visible again after 2hours.

 

 

Thanks,

Abdul

@Abdul333 In that case, new field which you created should be of Date/time type and populate current date/time into it when email is sent. Based on that date/time present in that new field, you can write a logic of 2 hours and use in condition field of UI action.

Share you script include code here.

@SANDEEP28 Please find the below Script Include.

 

var IncidentReminder = Class.create();
IncidentReminder.prototype = {
    initialize: function() {},
 
    reminderButtonVisibility: function(incidentObj) {
    // Add proper condition to determine if the button should be shown
        var gdt1 = new GlideDateTime(incidentObj.sys_updated_on);
        var hours1 = 60 * 60 * 1; // 2 hours in seconds
        gdt.addSeconds(60); //testing for after 60 seconds
        var todayDateTime1 = new GlideDateTime();
        var previousAssignmentGroups = [];
        if (incidentObj.u_previous_assignment_groups)
            previousAssignmentGroups = incidentObj.u_previous_assignment_groups.split(',');
 var isUserPartOfPreviousAssignmentGroups = false;
        if (previousAssignmentGroups.length > 0) {
            for (var i = 0; i < previousAssignmentGroups.length; i++) {
                var grMember = new GlideAggregate('sys_user_grmember');
                grMember.addQuery('user', gs.getUserID());
                grMember.addQuery('group', previousAssignmentGroups[i]);
                grMember.query();
                if (grMember.next()) {
                    isUserPartOfPreviousAssignmentGroups = true;
                    break;
                }
            }
        }
    var isUserPartOfCurrentAssignmentGroups = gs.getUser().isMemberOf(incidentObj.assignment_group.getDisplayValue());
        if (isUserPartOfCurrentAssignmentGroups)
            return false;
        if (incidentObj.state == 2 && incidentObj.assignment_group && !incidentObj.assigned_to && (todayDateTime1.getDisplayValue() > gdt1.getDisplayValue()) && isUserPartOfPreviousAssignmentGroups)
            return true;
        else
            return false;
    },

var grSla = new GlideRecord('contract_sla');
if (grSla.get('name', incidentObj.assignment_group.getDisplayValue())) {
var gsSchedule = new GlideSchedule(grSla.getValue('schedule'));
var todayDateTime = new GlideDateTime(); //GlideDateTime object representing the current date and time.
if (gsSchedule.isInSchedule(todayDateTime)) {
return true;
}
// If the current time is within the schedule, return true.
else {
return false; // If the current time is outside the schedule, return false.
}

} else {
return false; // If no record with the given group name is found, return false.
}

} else {
return false;
}
},

 

type: 'IncidentReminder'
};

 

Thanks,

Abdul