UI Action Script for request info

Mohamed Elsayed
Tera Expert

Hi All,

 

In the UI Action (Request Info), we have the below script, when we click on request info, we need to:

1- scroll down to the field called (Awaiting reason) and choose the relevant reason e.g., waiting customer.

2- Add additional comment.

 

Can anyone update the below script to behave as follow:

when request info is clicked, a popup shows to ask about both fields (Awaiting reason & additional comment)?

 

 

 

function checkawaitingtype() {
    var awaiting_reason = g_form.getValue('u_awaiting_info_reason');
	var com = g_form.getValue('comments');
    g_form.setDisplay('u_awaiting_info_reason', true);
    g_form.setMandatory('u_awaiting_info_reason', true);
    if (awaiting_reason == '') {
        alert('Please fill awaiting info reason');
    }else if(com ==''){
		alert('Please specify details in comments');
		g_form.setMandatory('comments', true);
	} else {
        gsftSubmit(null, g_form.getFormElement(), 'requestMoreInformation');
    }
}
if (typeof window == 'undefined')
    updateticket();


function updateticket() {
    new global.StateFlow().processFlow(current, '9a028a63c3123100d6d210c422d3ae11', 'manual');
    action.setRedirectURL(current);
}

 

 

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

This should help you get started: 

function checkawaitingtype() {
    if (typeof window === 'undefined') {
        updateticket();
    } else {

        var myModal = new GlideModal('awaiting_info_modal', false);
        myModal.setTitle('Provide Awaiting Info Details');

        var modalBody = '<div>' +
            '<label for="awaiting_reason">Awaiting Info Reason</label>' +
            '<input type="text" id="awaiting_reason" style="width: 100%;" />' +
            '<label for="comments" style="margin-top: 10px;">Additional Comments</label>' +
            '<textarea id="comments" rows="4" style="width: 100%;"></textarea>' +
            '</div>';

        myModal.setBody(modalBody, false, false);

        myModal.addDecoration({
            text: 'OK',
            color: 'primary',
            id: 'ok_button'
        });
        myModal.addDecoration({
            text: 'Cancel',
            color: 'secondary',
            id: 'cancel_button'
        });

        var okFunction = function () {
            var awaiting_reason = document.getElementById('awaiting_reason').value;
            var comments = document.getElementById('comments').value;

            if (awaiting_reason === '') {
                alert('Please fill awaiting info reason');
            } else if (comments === '') {
                alert('Please specify details in comments');
            } else {
                g_form.setValue('u_awaiting_info_reason', awaiting_reason);
                g_form.setValue('comments', comments);
                g_form.setDisplay('u_awaiting_info_reason', true);
                g_form.setMandatory('u_awaiting_info_reason', true);
                g_form.setMandatory('comments', true);
                gsftSubmit(null, g_form.getFormElement(), 'requestMoreInformation');
                myModal.destroy();
            }
        };

        var cancelFunction = function () {
            myModal.destroy();
        };

        document.getElementById('ok_button').onclick = okFunction;
        document.getElementById('cancel_button').onclick = cancelFunction;

        myModal.render();
    }
}

function updateticket() {
    new global.StateFlow().processFlow(current, '9a028a63c3123100d6d210c422d3ae11', 'manual');
    action.setRedirectURL(current);
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

3 REPLIES 3

Mark Manders
Mega Patron

This should help you get started: 

function checkawaitingtype() {
    if (typeof window === 'undefined') {
        updateticket();
    } else {

        var myModal = new GlideModal('awaiting_info_modal', false);
        myModal.setTitle('Provide Awaiting Info Details');

        var modalBody = '<div>' +
            '<label for="awaiting_reason">Awaiting Info Reason</label>' +
            '<input type="text" id="awaiting_reason" style="width: 100%;" />' +
            '<label for="comments" style="margin-top: 10px;">Additional Comments</label>' +
            '<textarea id="comments" rows="4" style="width: 100%;"></textarea>' +
            '</div>';

        myModal.setBody(modalBody, false, false);

        myModal.addDecoration({
            text: 'OK',
            color: 'primary',
            id: 'ok_button'
        });
        myModal.addDecoration({
            text: 'Cancel',
            color: 'secondary',
            id: 'cancel_button'
        });

        var okFunction = function () {
            var awaiting_reason = document.getElementById('awaiting_reason').value;
            var comments = document.getElementById('comments').value;

            if (awaiting_reason === '') {
                alert('Please fill awaiting info reason');
            } else if (comments === '') {
                alert('Please specify details in comments');
            } else {
                g_form.setValue('u_awaiting_info_reason', awaiting_reason);
                g_form.setValue('comments', comments);
                g_form.setDisplay('u_awaiting_info_reason', true);
                g_form.setMandatory('u_awaiting_info_reason', true);
                g_form.setMandatory('comments', true);
                gsftSubmit(null, g_form.getFormElement(), 'requestMoreInformation');
                myModal.destroy();
            }
        };

        var cancelFunction = function () {
            myModal.destroy();
        };

        document.getElementById('ok_button').onclick = okFunction;
        document.getElementById('cancel_button').onclick = cancelFunction;

        myModal.render();
    }
}

function updateticket() {
    new global.StateFlow().processFlow(current, '9a028a63c3123100d6d210c422d3ae11', 'manual');
    action.setRedirectURL(current);
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

 

Thanks, you are helping me in every single question 😊

 

The field (Awaiting Info reason) is a reference field and has four values and I want it to be populated on the popup. So, I took your code and updated it using ChatGPT to reflect this change and it gave me the below code. However, both codes (Yours and from ChatGPT) do not show the buttons (OK & Cancel) on the popup.

 

function checkawaitingtype() {
    if (typeof window === 'undefined') {
        updateticket();
    } else {
        var myModal = new GlideModal('awaiting_info_modal', false);
        myModal.setTitle('Provide Awaiting Info Details');

        // Fetch options for the dropdown from the u_awaiting_info_reason field
        var awaitingReasonOptions = getAwaitingReasonOptions(); // Implement this function

        var modalBody = '<div>' +
            '<label for="awaiting_reason">Awaiting Info Reason</label>' +
            '<select id="awaiting_reason" style="width: 100%;">' +
            '<option value="">Select Awaiting Info Reason</option>';

        // Populate dropdown options dynamically
        awaitingReasonOptions.forEach(function (option) {
            modalBody += '<option value="' + option.value + '">' + option.label + '</option>';
        });

        modalBody += '</select>' +
            '<label for="comments" style="margin-top: 10px;">Additional Comments</label>' +
            '<textarea id="comments" rows="4" style="width: 100%;"></textarea>' +
            '</div>';

        myModal.setBody(modalBody, false, false);

        myModal.addDecoration({
            text: 'OK',
            color: 'primary',
            id: 'ok_button'
        });
        myModal.addDecoration({
            text: 'Cancel',
            color: 'secondary',
            id: 'cancel_button'
        });

        var okFunction = function () {
            var awaiting_reason = document.getElementById('awaiting_reason').value;
            var comments = document.getElementById('comments').value;

            if (awaiting_reason === '') {
                alert('Please select an awaiting info reason');
            } else if (comments === '') {
                alert('Please specify details in comments');
            } else {
                // Populate the Awaiting Info Reason field
                g_form.setValue('u_awaiting_info_reason', awaiting_reason);
                g_form.setValue('comments', comments);
                g_form.setDisplay('u_awaiting_info_reason', true);
                g_form.setMandatory('u_awaiting_info_reason', true);
                g_form.setMandatory('comments', true);
                gsftSubmit(null, g_form.getFormElement(), 'requestMoreInformation');
                myModal.destroy();
            }
        };

        var cancelFunction = function () {
            myModal.destroy();
        };

        document.getElementById('ok_button').onclick = okFunction;
        document.getElementById('cancel_button').onclick = cancelFunction;

        myModal.render();
    }
}

function updateticket() {
    new global.StateFlow().processFlow(current, '9a028a63c3123100d6d210c422d3ae11', 'manual');
    action.setRedirectURL(current);
}

// Implement this function to fetch options from the u_awaiting_info_reason field
function getAwaitingReasonOptions() {
    // Replace with your logic to retrieve options (e.g., from a REST API or predefined list)
    return [
        { value: '1', label: 'Awaiting Contact' },
        { value: '2', label: 'Awaiting Change' },
		{ value: '3', label: 'Awaiting Problem' },
        { value: '4', label: 'Awaiting Vendor' }
        // Add more options as needed
    ];
}

Mohamed Elsayed
Tera Expert

Hi guys, 

 

Any help 🙂, I still cannot see the buttons (Ok & Cancel) on the pop-up.

 

Thanks