Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to destroy GlideModel in workspace using UI action?

Sneha_Krishna1
Tera Contributor

Hi All,
My requirement is to destroy GlideModel in workspace after validation successful.

I created one UI page, below is the code of the UI page 

function validateCode() {
    var inputFieldValue = gel('inputField').value;
    var sendData = new GlideAjax("VerifyUser");
    sendData.addParam('sysparm_name', 'sendData');
    sendData.getXMLAnswer(getData);
    function getData(answer) {
        var detail = answer.split(',');
        var code = detail[0];
        var view = detail[1];
        var record = detail[2];
        var assigned = detail[3];
        if (inputFieldValue == code) {
            call('pass');
            alert('Validation successful!');
            if (view == 'native')
                GlideModal.get().destroy();

            if (view == 'workspace')
                GlideDialogWindow.get().destroy();

        } else {
            call('fail');
            alert('Validation failed. Code does not match');
        }
        function call(output) {
            var send = new GlideAjax("VerificationLog");
            send.addParam('sysparm_name', 'createRecord');
            send.addParam('sysparm_result', output);
            send.addParam('sysparm_record', record);
            send.addParam('sysparm_verify', assigned);
            send.getXMLAnswer(getResponse);
            function getResponse(response) {
                //console.log("Completed");
            }
        }
    }
}

and UI action workspace client script is 
 var ui_page_id = 'f5f3b239db95ce9005edd9fcd39619b6'; // Specify the ID of the UI Page to be displayed in the modal
        g_modal.showFrame({
            url: '/ui_page.do?sys_id=' + ui_page_id,// Construct the URL of the UI Page using its sys_id
            title: 'Verification needed',// Set the title of the modal dialog
            size: 'lg', // Specify the size of the modal dialog (lg for large)
            height: 350 // Set the height of the modal dialog
        });

Can anyone help me how can I destroy this model in workspace?

 

 

 

6 REPLIES 6

@Ankur Bawiskar 
I want to display messages instead of alerts in UI page.

below is my UI page scripts : 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <div class = "jumbotron">
    <label for="verificationCodeMsg">A verification code has been sent to XXXXXX@abc.com (receiver email). Please check your spam folder if you do not see it your inbox.</label>
        <label for="inputField">Enter Code:</label>
        <input type="text" id="inputField" class = "form-control" pattern="\d{4}" maxlength="4">
        </input>
    </div>
    <button onclick="validateCode()" class = "btn btn-primary">Validate</button>
</j:jelly>
 
And client script:
 var inputFieldValue = gel('inputField').value;
    var sys_record = g_form.getUniqueValue();

    // AJAX request

    var sendData = new GlideAjax("VerifyUser");
    sendData.addParam('sysparm_name', 'sendData'); // Specify the method to call on the server-side
    sendData.addParam('sysparm_record', sys_record);
    sendData.getXMLAnswer(getData);

    function getData(answer) {
        var jsonData = JSON.parse(answer);
        var code = jsonData.code;
        var view = jsonData.view;
        var assigned = g_scratchpad.userDetails.assigned;

        // Check if the input code matches the received code
        if (inputFieldValue == code) {
            call('pass'); // Call a function to handle the successful validation and pass the result as 'pass'
            alert('Validation successful!'); // Display an alert indicating successful validation
           
           
            if (view == 'native') // Check if the view type is 'native'
                GlideModal.get().destroy(); // Close the modal if the view is 'native'

            if (view == 'workspace') {
                window.location.href = window.location.href + '&sysparm_next_pg=true';
            }
        } else {
            call('fail');
            alert('Validation failed. Code does not match');
        }
 
Can you help me on this, how can I display messages instead of alerts?

 

nikhilmadhe
Tera Contributor

Hi @Sneha_Krishna1 , 

To close the UI page that is opened using g_modal.showFrame(), you need to include the OOTB UI script named "SPMGmodalIframeMsgHelper" in your UI page jelly script as first line of your code in this way which 

i have mentioned below.

 <g:requires name="SPMGmodalIframeMsgHelper.jsdbx"></g:requires>
And to close your modal you can  write the code in this  way in your jelly script and bind the function with the close button.
<script>
     function cancel() {
            iframeMsgHelper.cancel();
      }
 </script>