- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 07:56 AM
I have Created an UI Action button on Location Table.
When I click on that button, a Dialog Form of Asset table should open with Location Prepopulated.
There are 2 scenarios:
I can search for an existing asset record (monitor, IP Phone, headsets or laptop) by scanning serial number into appropriate field and search.
If asset record exists in ServiceNow, display the results and allow me to scan Asset Tag into appropriate field. When I commits the update the asset record is updated and relationship between asset and location is created.
If asset record does not exist in ServiceNow display form that allows me to create a new asset record (existing functionality). Once form is completed and I commits the update create a new asset record and create relationship between asset and location.
This is the UI Action Button I created.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 07:26 AM
Hi @rahul16 ,
For this you can create a UI page with input textbox and button. Enter the asset tag in the textbox and click on the search button. On click of search button, following things will happen:
1. If any record in asset already exist with that asset tag name, that record will open in popup. You can modify the form and update
2. If it do not exist, it will open the new form where location is prepopulate.
Below is the solution:
Step 1. Create a UI Page with input textbox and Search button
Name : Hardware Scan
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">
<div class="col-xs-10 col-sm-9 col-md-6 col-lg-5 form-field input_controls">
<input name= "snumber" type = "text" id="sno" class="form-control"></input> <button onClick = "searchHardware()">Search</button>
</div>
</j:jelly>
Client Script:
function searchHardware() {
var sNumber = document.getElementById("sno").value;
var ga = new GlideAjax("scanHardware");
ga.addParam("sysparm_name", 'findAsset');
ga.addParam("tag", sNumber);
ga.getXML(setResponseDialog);
}
function createHardware() {
var ga = new GlideAjax("scanHardware");
ga.addParam("sysparm_name", 'CreateAsset');
ga.addParam("location", g_form.getUniqueValue());
ga.getXML(setResponseCreateDialog);
}
function setResponseDialog(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var gdw = new GlideModal('show_form');
gdw.setTitle("title");
gdw.setSize(750);
gdw.setPreference('table', 'alm_asset');
if (answer != "") {
gdw.setPreference('sys_id', answer);
gdw.render();
} else
createHardware();
}
function setResponseCreateDialog(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var gdw = new GlideModal('show_form');
gdw.setTitle("title");
gdw.setSize(750);
gdw.setPreference('table', 'alm_asset');
gdw.setPreference('sys_id', answer);
gdw.render();
}
2. Create a script include
Name : scanHardware
script:
var scanHardware = Class.create();
scanHardware.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findAsset: function() {
var assetTag = this.getParameter("tag");
var asset = new GlideRecord("alm_hardware");
if(asset.get("asset_tag",assetTag))
return asset.getValue("sys_id");
else
return "";
},
CreateAsset: function() {
var assetloc = this.getParameter("location");
var asset = new GlideRecord("alm_hardware");
asset.initialize();
asset.location = assetloc;
var rcrd = asset.insert();
return rcrd+"";
},
type: 'scanHardware'
});
3. Create a client callable UI action in location table and call the UI page:
var dialog = new GlideModal("Scan Hardware")
dialog.setTitle("My Page")
dialog.render();
4. Open any record of the location table and click on the button created > Enter the asset tag > click on search button:
If Record exist with such asset tag, record's form will display which can be updated
If record do not exist
It will open a new asset record with location pre-populated
I Hope this helps.
Please mark this helpful if this helps and mark as correct if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 07:26 AM
Hi @rahul16 ,
For this you can create a UI page with input textbox and button. Enter the asset tag in the textbox and click on the search button. On click of search button, following things will happen:
1. If any record in asset already exist with that asset tag name, that record will open in popup. You can modify the form and update
2. If it do not exist, it will open the new form where location is prepopulate.
Below is the solution:
Step 1. Create a UI Page with input textbox and Search button
Name : Hardware Scan
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">
<div class="col-xs-10 col-sm-9 col-md-6 col-lg-5 form-field input_controls">
<input name= "snumber" type = "text" id="sno" class="form-control"></input> <button onClick = "searchHardware()">Search</button>
</div>
</j:jelly>
Client Script:
function searchHardware() {
var sNumber = document.getElementById("sno").value;
var ga = new GlideAjax("scanHardware");
ga.addParam("sysparm_name", 'findAsset');
ga.addParam("tag", sNumber);
ga.getXML(setResponseDialog);
}
function createHardware() {
var ga = new GlideAjax("scanHardware");
ga.addParam("sysparm_name", 'CreateAsset');
ga.addParam("location", g_form.getUniqueValue());
ga.getXML(setResponseCreateDialog);
}
function setResponseDialog(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var gdw = new GlideModal('show_form');
gdw.setTitle("title");
gdw.setSize(750);
gdw.setPreference('table', 'alm_asset');
if (answer != "") {
gdw.setPreference('sys_id', answer);
gdw.render();
} else
createHardware();
}
function setResponseCreateDialog(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var gdw = new GlideModal('show_form');
gdw.setTitle("title");
gdw.setSize(750);
gdw.setPreference('table', 'alm_asset');
gdw.setPreference('sys_id', answer);
gdw.render();
}
2. Create a script include
Name : scanHardware
script:
var scanHardware = Class.create();
scanHardware.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findAsset: function() {
var assetTag = this.getParameter("tag");
var asset = new GlideRecord("alm_hardware");
if(asset.get("asset_tag",assetTag))
return asset.getValue("sys_id");
else
return "";
},
CreateAsset: function() {
var assetloc = this.getParameter("location");
var asset = new GlideRecord("alm_hardware");
asset.initialize();
asset.location = assetloc;
var rcrd = asset.insert();
return rcrd+"";
},
type: 'scanHardware'
});
3. Create a client callable UI action in location table and call the UI page:
var dialog = new GlideModal("Scan Hardware")
dialog.setTitle("My Page")
dialog.render();
4. Open any record of the location table and click on the button created > Enter the asset tag > click on search button:
If Record exist with such asset tag, record's form will display which can be updated
If record do not exist
It will open a new asset record with location pre-populated
I Hope this helps.
Please mark this helpful if this helps and mark as correct if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 12:56 AM
Hi @rahul16 ,
Could you please update if your issue got resolved? If yes, please help us close this thread so that others could benifit from this post.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 08:07 AM
Hi @rahul16 ,
Could you please mark Accept as Solution if this solves your issue. This will help in closing this thread and will help others with similar issue reach to a solution. If you are still having issue please let us know.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 01:36 PM
Hi @kamlesh kjmar ,
This response is awesome and almost exactly what I'm looking for. However, I'm having an issue when I try to replicate it. (I'm doing it on my sc_task table , not location table) which is easy enough to change.
When I click the UI action button, it takes me to the actual UI Action and doesn't execute the pop-up modal...?
Also, I'd like to change this so that it could search on either asset_tag or serial_number fields (whichever is not empty within the pop-up). If it doesn't find either, then pop-up "No assets found" and not create a new asset.
Any help would be great!