Based on selection state and substate changes

Shaik22
Tera Expert

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);

Shaik22_0-1680008473471.png

 

4 REPLIES 4

Vigneshwara Red
Tera Contributor

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;

})();

No,it is not working.

Shaik,
Can you please confirm if you have modified the above script based on what to update.
Thanks

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;

})();