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.

Need help in passing value from UI Page to UI action?

saint
Tera Expert

Hi Experts,

 

I have a scenarios where,

List choice UI action is on a location table, when I select multiple locations and click the UI action, a record is created for each selected location in one of the custom table, I have achieved this functionality.

Now the further requirement is when user selects the locations and clicks the UI action, he/she should also be able to enter a date which will then be populated in a date field on the new record created in custom table. Let me know if I can solve this with any method other than below which I'm trying.

 

I am using a UI page to show a popup of date field for user input, but now I cannot use my script in UI action itself to pass the values of selected locations. What I want to achive now is  pass the values of selected locations from UI page to UI action to process further or ( pass it from UI page to its processing script and then to SI for updation )

 

Please let me know if any more info or inputs are needed. 

 

Thanks 

1 ACCEPTED SOLUTION

@saint 

can you try this?

    modal.setPreference('sysparm_entity',selected_entities);

Method 1:

 <input type="hidden" name="record_sysIds" id="record_sysIds" value="${sysparm_entity}"/>

Method 2:

<g:evaluate var="jvar_id" expression="RP.getWindowProperties().sysparm_entity"/>

 <input type="hidden" name="record_sysIds" id="record_sysIds" value="${jvar_id}"/>

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

15 REPLIES 15

I tried this, it still returns empty. I'm using jelly, for buttons I have used <button> tag directly.

@saint 

please use <g:dialog>

can you share your updated UI page HTML and client script?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

let me share the code now

 

UI ACTION: 

function launch() {

    var selected_entities = g_list.getChecked();
    alert(selected_entities); // SHOWS ALL SYSIDs
    var modal = new GlideDialogWindow('sn_risk_advanced_scopeduedate');
    modal.setTitle('Select Due Date');
    modal.setPreference('sysparm_view', 'default');
    modal.setPreference('entity',selected_entities);
    modal.render();
}

 

UI PAGE 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">
                        <g:ui_form id="scope">
                 <g:evaluate var="jvar_id" expression="RP.getParameterValue('entity')"/>
                 <input type="hidden" value="${jvar_id}" id="record_sysIds"/>
                 <table>
                         <tr>
                                 <td>Due date</td>
                                 <td><input type="date" id="date_id" name="date"/></td>                              
                         </tr>
                                                                                <tr>
                                <td><button type="reset" onClick="onReset()" class="btn-primary btn" name="reset" id="reset" style="min-width: 5em">${gs.getMessage('Reset')}</button></td>
        <td><button type="submit" onClick="onSubmit()" class="btn-primary btn" name="submit" id="submit" style="min-width: 5em">${gs.getMessage('Submit')}</button></td>
                                </tr>
                       
                 </table>
        </g:ui_form>

</j:jelly>

 

UI PAGE CLIENT SCRIPT

 

function onReset() {

    document.getElementById("scope").reset();
}


function onSubmit() {

                alert("Inside submit");
    var date = gel('date_id').value;
    var sysIds = gel('record_sysIds').value;
                alert("date : " + date);
                alert("SysId : " + gel('record_sysIds').value);

    var ga = new GlideAjax('sn_risk_advanced.LRAUtils');
    ga.addParam('sysparm_name', 'createScopeForEntity');
    ga.addParam('sysparm_selected_entities', sysIds);
    ga.addParam('sysparm_due_date', date);
    ga.getXML(doAfterServerResponse);

    /*Throws error alert when entity scope already exists*/
    function doAfterServerResponse(response) {
        var ans = response.responseXML.documentElement.getAttribute("answer");
        if (ans > 0)
            alert("Few records could not be added as record with same risk assessment methodology and entity already exists");
        g_navigation.reloadWindow();
    }

}

 

 

@Ankur Bawiskar I tried passing a string value in UI action, as below

 modal.setPreference('entity',"SYSID_OF_A_RECORD");

 Still in the onSubmit CS of UI page alert came as null.

the value is not passing through

@saint 

I think you are in scoped app.

Can you please try this?

 <input type="hidden" name="record_sysIds" id="record_sysIds" value="${entity}"/>

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader