- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2023 11:23 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 05:48 AM
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}"/>
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 01:56 AM
Hi All, ading my code below, **please reply to the original post as I may need to edit or delete this reply in future.
UI Action SCRIPT:
function launch() {
var selected_entities = g_list.getChecked(); // I want to pass this value till SI to create new records
***NEED HELP IN THIS****CHECK ABOVE COMMENT****
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">
<table>
<tr>
<td>Due date</td>
<td><input type="date" id="date_id" name="date"/></td>
<td><input type="hidden" id="jvar_answer" name="jvar_answer" value=""/></td>
</tr>
<tr>
<td><input type="reset" onClick="onReset()"/></td>
<td><input type="submit" onClick="onSubmit()"/></td>
</tr>
</table>
</g:ui_form>
</j:jelly>
UI Page Client Script:
function onReset() {
document.getElementById("scope").reset();
}
function onSubmit() {
alert("test"); // this pops ups in testing
gel("jvar_answer").value = g_list.getChecked(); // working on this to see if I can pass value
}
UI Page PROCESSING SCRIPT:
alert(jvar_answer);
var ga = new GlideAjax('sn_risk_advanced.LRAUtils');
ga.addParam('sysparm_name', 'createScopeForEntity');
ga.addParam('sysparm_selected_entities', jvar_answer);
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();
}
Script Include:
createScopeForEntity: function() {
var methodology;
var due_date;
var selected_entities;
var entities;
var count = 0;
var en;
/*fetches the methodology where state is published and assesment type is LRA*/
var gr1 = new GlideRecord('sn_risk_advanced_risk_assessment_methodology');
gr1.addEncodedQuery('state=2^u_assessment_type=0');
gr1.query();
while (gr1.next()) {
methodology = gr1.getValue('sys_id');
}
/*uses the ajax call from UI action to pass the selected entities */
due_date = this.getParameter('sysparm_due_date');
selected_entities = this.getParameter('sysparm_selected_entities');
entities = selected_entities.split(',');
/*loops the selected entities*/
for (var i = 0; i < entities.length; i++) {
en = entities[i];
/*checks if the entity-methodology scope already exists*/
var gr2 = new GlideRecord('sn_risk_advanced_risk_assessment_scope');
gr2.addQuery('entity', en);
gr2.query();
while (gr2.next()) {
count++;
}
/*creates the new scope for entity-methodology*/
var gr = new GlideRecord('sn_risk_advanced_risk_assessment_scope');
gr.initialize();
gr.setValue('risk_assessment_methodology', methodology);
gr.setValue('entity', en);
gr.setValue('u_due_date', due_date)
gr.insert();
}
/*return if relationship exists*/
if (count > 0) {
return count;
}
}