UI Page not rendering when passing parameters from UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2023 02:33 AM
Hi
I have a UI action (client with Onclick) on Incident, in which I am trying to pass the SysId and CI to a UI page. However, the dialog window does not render unless I remove the "dialog.addParam" lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2023 03:57 AM
@Ankur Bawiskar I have included my UI page for context:
<?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>
.float-container {
color: #4a4d4b;
width: 600px;
border-radius: 0px;
}
.float-child {
padding:30px;
width: 300px;
float: left;
}
label.required::before {
content: '*';
margin-right: 4px;
color: red;
}
label.notrequired::before {
content: '*';
margin-right: 4px;
color: grey;
}
.submit {
background :#245ba3;
color: #ffffff
}
</style>
<!-- Build Form and Fields -->
<g:ui_form action="/update_asset.php">
<g:evaluate var="jvar_ci"
expression="RP.getWindowProperties().get('cmdb_ci')" />
<g:evaluate var="jvar_incident"
expression="RP.getWindowProperties().get('incident')" />
<div class="float-container">
<h3>Update Asset</h3>
<div class="float-child">
<label id="incident" for="incident" >Old Asset:</label>
<g:ui_reference class="form-control" name="incident" id="incident" table="incident" onchange="onChange_asset()" required="required" value="${jvar_sys_id}" mandatory="true" />
<label id="old_asset_label" for="old_asset" >Old Asset:</label>
<g:ui_reference class="form-control" name="old_asset" id="old_asset" table="alm_asset" onchange="onChange_asset()" required="required" />
<label id="new_asset_label" for="new_asset" >New Asset</label>
<g:ui_reference class="form-control" name="new_asset" id="new_asset" table="alm_asset" onchange="onChange_asset()" />
<label id="new_asset_tag_label" for="new_asset_tag">New Asset Tag:</label>
<input class="form-control" type="text" id="new_asset_tag" name="new_asset_tag" onchange="onChange_asset()"></input>
<br></br>
<g:dialog_buttons_ok_cancel ok_id="submitData" ok="return continueOK()" ok_type="button" ok_text="${gs.getMessage('Submit')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="return continueCancel()"/>
</div>
<div class="float-child">
<label id="assigned_to_label" for="assigned_to" >Assigned to:</label>
<g:ui_reference class="form-control" type="reference" id="assigned_to" name="assigned_to" table="sys_user" onchange="onChange_asset()"/>
<label id="location_label" for="location" >Location:</label>
<g:ui_reference class="form-control" type="reference" id="location" name="location" table="cmn_location" onchange="onChange_asset()"/>
<label id="department_label" for="department" >Department:</label>
<g:ui_reference class="form-control" type="reference" id="department" name="department" table="cmn_department" onchange="onChange_asset()"/>
<label id="comments_label" for="comments">Comments:</label>
<textarea class="form-control" rows = "5" cols = "60" id="comments" name = "comments" onchange="onChange_asset()">
</textarea>
<!-- <input class="field2" type="text area" id="Comments" name="Comments"></input><br></br> -->
</div>
</div>
</g:ui_form>
</j:jelly>
<label id="incident" for="incident" >Old Asset:</label>
<g:ui_reference class="form-control" name="incident" id="incident" table="incident" onchange="onChange_asset()" required="required" value="${jvar_sys_id}" mandatory="true" />
<label id="old_asset_label" for="old_asset" >Old Asset:</label>
<g:ui_reference class="form-control" name="old_asset" id="old_asset" table="alm_asset" onchange="onChange_asset()" required="required" />
document.getElementById('old_asset_label').setAttribute("class", "required");
document.getElementById('new_asset_label').setAttribute("class", "required");
document.getElementById('new_asset_tag_label').setAttribute("class", "notrequired");//Sets the class on the label to provide the asterisks for required value
document.getElementById('assigned_to_label').setAttribute("class", "required");
document.getElementById('location_label').setAttribute("class", "required");
document.getElementById('department_label').setAttribute("class", "required");
document.getElementById('comments_label').setAttribute("class", "required");
function onChange_asset(){//Function to set "New Asset Tag" field to mandatory if the asset tag doesn't start with "NHSG".
var oldAsset = document.getElementById('old_asset').value;
if (oldAsset != ""){
//alert(oldAsset);
document.getElementById('old_asset_label').setAttribute("class", "notrequired");
}
if (oldAsset == ""){
// alert("oldAsset");
document.getElementById('old_asset_label').setAttribute("class", "required");
document.getElementById('old_asset').setAttribute("mandatory", "true");
}
var assetTag = document.getElementById("new_asset").value;//Get the SysId of the asset in the "New Asset" field
//check if the asset field is not empty for the onChange script to run
if (assetTag != ""){
document.getElementById('new_asset_label').setAttribute("class", "notrequired");
var gr = new GlideRecord("alm_asset");//Lookup the asset using the SysId
gr.addQuery("sys_id", assetTag);
gr.query();
while (gr.next()) {
//alert(gr.asset_tag);
var assetTag2 = gr.asset_tag.substring(0,4);//Get the first 4 characters from the "Asset Tag" field on the record
if (assetTag2 != "NHSG") {
//set "New Asset Tag mandatory to true"
document.getElementById('new_asset_tag_label').setAttribute("class", "required");
document.getElementById('new_asset_tag').setAttribute("required", "true");
}
var newAssetTag = document.getElementById('new_asset_tag').value;
if (assetTag2 == "NHSG" ||newAssetTag != "") {
//set "New Asset Tag mandatory to false"
document.getElementById('new_asset_tag_label').setAttribute("class", "notrequired");
document.getElementById('new_asset_tag').removeAttribute("required");
}
}
}
var user = document.getElementById('assigned_to').value;
if (user != ""){
//alert(user);
document.getElementById('assigned_to_label').setAttribute("class", "notrequired");
}
if (user == ""){
// alert(user);
document.getElementById('assigned_to_label').setAttribute("class", "required");
}
var location = document.getElementById('location').value;
if (location != ""){
//alert(location);
document.getElementById('location_label').setAttribute("class", "notrequired");
document.getElementById('assigned_to_label').setAttribute("class", "notrequired");
}
if (location == ""){
// alert(location);
document.getElementById('location_label').setAttribute("class", "required");
}
var dept = document.getElementById('department').value;
if (dept != ""){
// alert(dept);
document.getElementById('department_label').setAttribute("class", "notrequired");
}
if (dept == ""){
//alert(dept);
document.getElementById('department_label').setAttribute("class", "required");
}
var comments = document.getElementById('comments').value;
if (comments != ""){
//alert(comments);
document.getElementById('comments_label').setAttribute("class", "notrequired");
}
if (comments == ""){
// alert(comments);
document.getElementById('comments_label').setAttribute("class", "required");
}
}
function continueOK(){
var oldAsset = document.getElementById('old_asset').value;
var assetTag = document.getElementById("new_asset").value;
var newAssetTag = document.getElementById('new_asset_tag').value;
var user = document.getElementById('assigned_to').value;
var location = document.getElementById('location').value;
var dept = document.getElementById('department').value;
var comments = document.getElementById('comments').value;
// var newAssetTag = document.getElementById('new_asset_tag').value;
if (oldAsset == ""||assetTag == ""||location == ""|| dept == ""||comments == ""){
//alert(oldAsset);
// document.getElementById('old_asset_label').setAttribute("class", "notrequired");
alert('Please complete mandatory fields.');
return false;
}
if(newAssetTag != ""){
var gr2=new GlideRecord("alm_asset");
gr2.addQuery("sys_id",oldAsset);
gr2.query();
while(gr2.next()){
var gr=new GlideRecord("alm_asset");
gr.addQuery("sys_id",assetTag);
gr.query();
while(gr.next()){
var old=gr2.asset_tag;
gr.asset_tag=newAssetTag;
alert(gr.asset_tag);
gr.location=location;
gr.department=dept;
gr.update;
gr.assigned_to=user;
gr.substatus= "--none--";
gr.install_status= "1";
gr.update;
gr.comments = "Replaced " + old + " - " + comments;
gr.company = "71f448c71b720510349f40c4e34bcbd3";
gr.update();
}
}
}
if(newAssetTag == ""){
//alert("test");
var gr4=new GlideRecord("alm_asset");
gr4.addQuery("sys_id",oldAsset);
gr4.query();
while(gr4.next()){
var gr3=new GlideRecord("alm_asset");
gr3.addQuery("sys_id",assetTag);
gr3.query();
while(gr3.next()){
var old2 = gr4.asset_tag;
gr3.location=location;
gr3.department=dept;
gr3.update;
gr3.assigned_to=user;
gr3.substatus= "--none--";
gr3.install_status= "1";
gr3.update;
gr3.comments = "Replaced " + old2 + " - " + comments;
gr3.company = "71f448c71b720510349f40c4e34bcbd3";
gr3.update();
}
}
}
if(oldAsset != ""){
//alert("test");
var gr6=new GlideRecord("alm_asset");
gr6.addQuery("sys_id",assetTag);
gr6.query();
while(gr6.next()){
var gr5=new GlideRecord("alm_asset");
gr5.addQuery("sys_id",oldAsset);
gr5.query();
while(gr5.next()){
var replacement = gr6.asset_tag;
gr5.location=location;
gr5.department=dept;
gr5.update;
gr5.substatus= "pending_disposal";
gr5.install_status= "7";
gr5.disposal_reason = comments;
gr5.update;
gr5.comments = "Replaced by " + replacement + " - " + comments;
gr5.company = "71f448c71b720510349f40c4e34bcbd3";
gr5.update();
}
}
}
alert("Assets updated");
GlideDialogWindow.get().destroy(); //Close the dialog window
//alert("Assets updated");: " + "/n " + old + " /n" + "State: Retired " + "/n"+ "Substate: Pending Disposal" + "/n" + "Disposal Reason: " + commments + "/n + New Asset: " + replacement);
}
//alert(gr.asset_tag);
//alert('Please enter a comment');
//alert("Please complete mandatory fields");
//}
function onCancel(){
GlideDialogWindow.get().destroy(); //Close the dialog window
}
//If comments are empty stop submission
//alert("New asset tag is required.");///use this on submit
//If comments are not empty do this...
//GlideDialogWindow.get().destroy(); //Close the dialog window
//g_form.setValue("comments", comments); //Set the 'Comments' field with comments in the dialog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2023 04:00 AM
you can check the logic I shared
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-30-2023 04:02 AM
@Ankur Bawiskar sorry, I'm not sure what you mean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2023 04:14 AM
please use the script I shared.
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-30-2023 04:15 AM