UI Action on Table A to update a record on Table B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 10:58 PM - edited 06-05-2023 10:59 PM
Hello Experts,
I have a custom table A where we create records to allocate multiple assets to different locations. On the Hardware table we have a reference field to table A record. I need to create a UI action on table A which on click should update the reference field on Hardware with the table A record name.
The purpose of the UI Action is to allow multiple asset record update based on a query criteria.
I wrote the below client callable UI Action on the custom table but it doesn't seem to update the Hardware record.
Any suggestion on what i am doing wrong would be great.
Table - Table A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 12:43 AM
Hi @Somujit1
check below comments
function addAsset() {
var answer = confirm("Are you sure you want add hardware assets to this deployment record?");
if (answer == false) {
return false;
}
if (typeof window == 'undefined')
assetReturn();
function assetReturn() {
var updateAsset = new GlideRecord("alm_hardware");
updateAsset.addEncodedQuery('stockroom=<location_name>^install_statusIN6,1^substatus=available'); //please provide proper sysid of stockroom here
updateAsset.query();
while (updateAsset.next()) {
updateAsset.reference_field_name = current.sys_id; // modify this and use proper field name.
updateAsset.update();
}
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 07:29 PM
Thanks for your reply @Voona Rohila. Updated the script as suggested, but it doesnt seem to updated the hardware record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 01:17 AM
Hi @Somujit1 ,
In order to use the server script in the UI action, you need to trigger it using gsftSubmit().
Please add an action name as well example : 'update_asset'
AND, the condition should be (current.state=='new'||current.state=='open')
Refer to this script below:
function addAsset() {
var answer = confirm("Are you sure you want add hardware assets to this deployment record?");
if (answer == false) {
return false;
}
else{
gsftSubmit(null, g_form.getFormElement(), "update_asset")
}
if (typeof window == 'undefined')
assetReturn();
function assetReturn() {
var updateAsset = new GlideRecord("alm_hardware");
updateAsset.addEncodedQuery('stockroom=<location_name>^install_statusIN6,1^substatus=available'); //please provide proper sysid of stockroom here
updateAsset.query();
while (updateAsset.next()) {
updateAsset.reference_field_name = current.sys_id; // modify this and use proper field name.
updateAsset.update();
}
}
}
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 07:22 PM - edited 06-07-2023 07:27 PM
Hi @Karan Chhabra6 ,
Thanks for your reply.
I updated the script with the above changes suggested by you and as below, but it still doesnt seem to update the hardware record. Any suggestions to make it work?
Updated UI action script, action name and condition on custom table A -