UI page pop-up

NAIDILE S
Tera Contributor

Hi All 
I have a UI page , where I added this Issue with (choice field) and want that information to be on INC form . but the information is not getting populated .
Here , I'm creating Incident from Security incident , and Issue with info needs to populated on INC table
Note: Issue with is only on INC form not on Security incident form

NAIDILES_1-1694417261752.png

NAIDILES_2-1694417450226.png

Can anyone help me on this.

Thankyou

 

13 REPLIES 13

@Peter Bodelier 
Sure ill try it. and one more thing
say if i select "application service" in issue with other fields become mandatory or say readonly; on the pop up how can we do it?

You will have to implement a onChange function call (onchange="myFunction(this.value)") in the issue field, which sets a 'readonly' variable to true.

Use that variable within the other fields that need to become readonly. (readonly=$[setReadOnly])


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

HTML

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <style>
        .form-section {
            margin-bottom: 15px;
        }
        .form-control{
            border-color: #939593;
        }
    </style>
    <g:ui_form>
            <input type="hidden" id="secId" name="secId" value="${JS,HTML:sysparm_sys_id}"/>
            <input type="hidden" id="action" name="action" value="${JS,HTML:sysparm_action}"/>
            <input id="react" name="react" type="hidden" value="${JS,HTML:sysparm_react}" />
            <input id="resource_url" name="resource_url" type="hidden" value="${JS,HTML:sysparm_resource}" />
       
            <g:evaluate jelly="true">
                var jvar_secIncId = jelly.sysparm_sys_id;
                var secInc = new GlideRecord("sn_si_incident");
                var exist = secInc.get(jvar_secIncId);
                if (!exist)
                    secInc.newRecord();
                secInc;
            </g:evaluate>
            <div class="modal-body">
                <div class="row form-section">
                    <label for="ci" class="col-sm-3 section-title-top">${gs.getMessage('Configuration item')}</label>
                    <div class="col-sm-5 section-title-top">
                        <input readonly="true" id="ci" class="col-sm-9 form-control" type="text" name="ci" value="$[JS,HTML:secInc.getDisplayValue('cmdb_ci')]" aria-label="${JS,HTML:gs.getMessage('Configuration item')}"></input>
                    </div>
                </div>
                <div class="row form-section">
                    <label class="col-sm-3 section-title-top">${gs.getMessage('Location')}</label>
                    <div class="col-sm-5 section-title-top">
                        <input readonly="true" id="loc" class="col-sm-9 form-control" type="text" name="loc" value="$[JS,HTML:secInc.getDisplayValue('location')]" aria-label="${JS,HTML:gs.getMessage('Location')}"></input>
                    </div>
                </div>
               
                <j:if test="${sysparm_action != 'change_request'}">
                    <div class="row form-section">
                        <div class="col-sm-3 section-title-top">${gs.getMessage('Impact')}</div>
                        <div class="col-sm-3">
                            <g:evaluate var="jvar_property">
                                var prop;
                                if ("${sysparm_action}" == "incident")
                                    prop = GlideChoiceList.getChoiceList('incident', 'impact');
                                else if ("${sysparm_action}" == "problem")
                                    prop = GlideChoiceList.getChoiceList('problem', 'impact');
                            </g:evaluate>
                            <select id="impact" class="form-control" name="impact" value="$[JS,HTML:secInc.impact]">
                                <g2:options choiceList="$[prop]" choiceValue="$[secInc.impact.toString()]" />
                            </select>
                        </div>
                    </div>
                   
                    <div class="row form-section">
                        <div class="col-sm-3 section-title-top">${gs.getMessage('Urgency')}</div>
                        <div class="col-sm-3">
                            <g:evaluate var="jvar_property">
                                var prop1;
                                if ("${sysparm_action}" == "incident")
                                    prop1 = GlideChoiceList.getChoiceList('incident', 'urgency');
                                else if ("${sysparm_action}" == "problem")
                                    prop1 = GlideChoiceList.getChoiceList('problem', 'urgency');
                            </g:evaluate>
                            <select id="urgency" class="form-control" name="urgency" value="$[JS,HTML:secInc.urgency]">
                                <g2:options choiceList="$[prop1]" choiceValue="$[secInc.urgency.toString()]" />
                            </select>
                        </div>
                    </div>

                    <!--Issue field on incident form-->
                    <div class="row form-section">
                    <div class="col-sm-3 section-title-top">${gs.getMessage('Issue with')}</div>
                        <div class="col-sm-3">
                            <g:evaluate var="jvar_property">
                                var prop2;
                                if ("${sysparm_action}" == "incident")
                                    prop2 = GlideChoiceList.getChoiceList('incident', 'u_choice_issue');
                                else if ("${sysparm_action}" == "problem")
                                    prop2 = GlideChoiceList.getChoiceList('problem', 'u_choice_issue');
                            </g:evaluate>
                            <select id="u_choice_issue" class="form-control" name="u_choice_issue" value="$[JS,HTML:secInc.u_choice_issue]">
                                <g2:options choiceList="$[prop2]" choiceValue="$[secInc.u_choice_issue.toString()]" />
                            </select>
                        </div>
                    </div>
                   

                </j:if>
               
                <j:if test="${sysparm_action == 'change_request'}">
                    <div class="row form-section">
                        <div class="col-sm-3 section-title-top">${gs.getMessage('Priority')}</div>
                        <div class="col-sm-3">
                            <g:evaluate var="jvar_property">
                                var prList = GlideChoiceList.getChoiceList('change_request', 'priority');
                            </g:evaluate>
                            <select id="priority" class="form-control" name="priority" aria-label="priority">
                                <g2:options choiceList="$[prList]" choiceValue="$[secInc.priority.toString()]" />
                            </select>
                        </div>
                    </div>
                </j:if>

                <div class="row form-section">
                    <label for="short_desc" class="col-sm-3 section-title-top">${gs.getMessage('Short description')}</label>
                    <div class="col-sm-9 section-title-top">
                        <input id="short_desc" class="col-sm-9 form-control" type="text" name="short_desc" value="$[JS,HTML:secInc.short_description]" aria-label="${JS,HTML:gs.getMessage('Short description')}"></input>
                    </div>
                </div>
                <div class="row form-section">
                    <label for="desc" class="col-sm-3 section-title-top">${gs.getMessage('Description')}</label>
                    <span class="col-sm-9 section-title-top">
                        <textarea id="desc" class="col-sm-9 form-control" rows="3" name="desc" aria-label="${JS,HTML:gs.getMessage('Description')}">${HTML:secInc.description}</textarea>
                    </span>
                </div>
            </div>
            <footer class="modal-footer">
                <!-- <g:dialog_buttons_ok_cancel ok="return onSubmit();" cancel="return onCancel();"/> -->
                <button class="btn-default btn" style="min-width: 5em" onclick="return onCancel();" name="cancel" id="cancel">${gs.getMessage('Cancel')}</button>
                <button class="btn-primary btn" onclick="return onSubmit();" name="submit" id="submit" style="min-width: 5em">${gs.getMessage('Submit')}</button>
            </footer>
    </g:ui_form>
</j:jelly>

Client Script 

function setCustomEvent() {
    if (typeof window.CustomEvent === "function") return false; //If not IE

    function CustomEvent(event, params) {
        params = params || {
            bubbles: false,
            cancelable: false,
            detail: undefined
        };
        var evt = document.createEvent('CustomEvent');
        evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
        return evt;
    }

    CustomEvent.prototype = window.Event.prototype;

    window.CustomEvent = CustomEvent;
}

function onCancel() {
    if (gel('react').value) {
        var event;
       
        //The following if-else is 'Event' polyfill for IE
        if (typeof(Event) === 'function') {
            event = new Event('SIR_WORKBENCH_POPUP_CANCEL');
        } else {
            event = document.createEvent('Event');
            event.initEvent('SIR_WORKBENCH_POPUP_CANCEL', true, true);
        }
        window.parent.dispatchEvent(event);
    } else
        GlideDialogWindow.get().destroy();
    return false;
}

function onSubmit() {
    window.setTimeout(function() {
        jQuery("#submit").prop('disabled', true);
    });
    var result = true;
    if (gel('react').value) {
        try {
            var body = {};
            if(gel('secId'))
                body['si_sys_id']= gel('secId').value;
           
            if(gel('short_desc'))
                body['short_desc']= gel('short_desc').value;
           
            if(gel('desc'))
                body['description']= gel('desc').value;
           
            if(gel('impact'))
                body['impact']= gel('impact').value;
           
            if(gel('urgency'))
                body['urgency']= gel('urgency').value;
           
            if(gel('ci'))
                body['cmdb_ci']= gel('ci').value;
           
            if(gel('loc'))
                body['location']= gel('loc').value;
           
            if(gel('priority'))
                body['priority']= gel('priority').value;
            // for Issue with field
            if(gel('u_choice_issue'))
                body['u_choice_issue']= gel('u_choice_issue').value;
           
            var restEndPoint = "/api/sn_app_secops_ui/v1/secops_ui_si_actions/" + gel('resource_url').value;
            var requestBody = JSON.stringify(body);
            var client = new XMLHttpRequest();
            client.open("post", restEndPoint);
            client.setRequestHeader('Accept', 'application/json');
            client.setRequestHeader('Content-Type', 'application/json');
            client.setRequestHeader("X-UserToken", g_ck);
            client.setRequestHeader("X-WantSessionNotificationMessages", true);

            client.onreadystatechange = function() {
                if (this.readyState == this.DONE) {
                    setCustomEvent();
                    params = {
                        detail: JSON.parse(this.response)
                    };
                    window.parent.dispatchEvent(new CustomEvent('SIR_WORKBENCH_POPUP_SUBMIT', params));
                    //console.log(JSON.parse(this.response));
                }
            };
            client.send(requestBody);
            return false;
        } catch (e) {
            return true;
        }
    }
    return true;
}

Processing Script

var securityIncident = new GlideRecord("sn_si_incident");
if (/^[0-9a-fA-F]{32}$/.test(secId))
    securityIncident.get(secId);
else
    secId = securityIncident.getUniqueIdentifier();
securityIncident.description = desc;
securityIncident.short_description = short_desc;

if (action == "change_request") {
    securityIncident.priority = priority;
    var changeRequest = (new SecurityIncidentUtils1()).createChangeFromSecurityIncident(securityIncident);
    if(changeRequest.indexOf("Error") == -1)
        gs.addInfoMessage(gs.getMessage("Change request {0} was created.", changeRequest));
    else
        gs.addErrorMessage(gs.getMessage("Could not create the Change Request."));
}
else if (action == "incident") {
    securityIncident.impact = impact;
    securityIncident.urgency = urgency;
    // Need urgency and impact together to generate Incident priority
    var incident = (new SecurityIncidentUtils1()).createIncidentFromSecurityIncident1(securityIncident);
    if(incident.indexOf("Error") == -1)
        gs.addInfoMessage(gs.getMessage("Incident {0} was created.", incident));
    else
        gs.addErrorMessage(gs.getMessage("Could not create the Incident."));
}
else if (action == "problem") {
    securityIncident.impact = impact;
    securityIncident.urgency = urgency;
    var prb = (new SecurityIncidentUtils1()).createProblemFromSecurityIncident(securityIncident);
    if (prb.indexOf("Error") == -1)
        gs.addInfoMessage(gs.getMessage("Problem {0} was created.", prb));
    else
        gs.addErrorMessage(gs.getMessage("Could not create the Problem."));
}
response.sendRedirect("sn_si_incident.do?sysparm_query=sys_id=" + secId);


Hi @NAIDILE S,

 

This UI Page looks to be just fine.
Did you adjust the SecurityIncidentUIActions script include to include this field as well?

 

OOTB it is this script, so you will need to add your u_choice_issue field there:

 

createIncident: function(input) {
        try {
            var securityIncident = new GlideRecord("sn_si_incident");
            securityIncident.get(input.si_sys_id);
            if (input.description) securityIncident.description = input.description;
            if (input.short_desc) securityIncident.short_description = input.short_desc;
            if (input.impact) securityIncident.impact = input.impact;
            if (input.urgency) securityIncident.urgency = input.urgency;
            if (input.priority) securityIncident.priority = input.priority;
            var incident = (new sn_si.SecurityIncidentUtils()).createIncidentFromSecurityIncident(securityIncident);
            if (incident.indexOf("Error") > -1)
                gs.addErrorMessage(gs.getMessage("Could not create Incident."));
            else
                gs.addInfoMessage(gs.getMessage("Incident {0} was created.", this.URLOpenNewTab(incident)));
        } catch(e) {
            gs.error(e);
        }
    },

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

ya i altered Script include