Based on selection state and substate changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 06:01 AM
Hello,
On a table there is a field 'asset' when we select multiple assets in related list these assets are shown.For example,there are three assets in related list in that i was selected only two assets and click on 'stock' button only those two assets state and sub state needs to change but the problem here is it is changing all the assets state and sub state.
UI action script:
function changeStateSubstate() {
gsftSubmit(null, g_form.getFormElement(), 'clear_stock_state');
}
var current_assets = current.u_assets.split(",");
for(var i=0;i<current_assets.length;i++)
{
if (current.getValue('u_assets')) {
var asset = new GlideRecord('alm_asset');
asset.addQuery('sys_id',current_assets[i]);
asset.query();
while (asset.next()) {
asset.install_status = '7';
asset.substatus = 'pending_disposal';
asset.update();
}
}
}
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 06:07 AM
Hi,
You can try below script and modify based on your requirement.
(function executeUIAction() {
var grList = g_list.getSelectedRecords();
if (grList.length == 0) {
alert("Please select at least one record to update.");
return false;
}
for (var i = 0; i < grList.length; i++) {
var gr = grList[i];
gr.setValue("field1", "new value");
gr.setValue("field2", "new value");
gr.update();
}
gs.getSession().refreshAll();
return true;
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 06:19 AM
No,it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 06:22 AM
Shaik,
Can you please confirm if you have modified the above script based on what to update.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 06:28 AM
I used this script.
function changeStateSubstate() {
gsftSubmit(null, g_form.getFormElement(), 'clear_stock_state');
}
(function executeUIAction() {
var grList = g_list.getSelectedRecords();
if (grList.length == 0) {
alert("Please select at least one record to update.");
return false;
}
for (var i = 0; i < grList.length; i++) {
var gr = grList[i];
gr.setValue("install_status", "7");
gr.setValue("substatus", "pending_disposal");
gr.update();
}
gs.getSession().refreshAll();
return true;
})();