Hi All, We have a script to update the hardware asset state and substate based on…
- User
Hi All,
We have a script to update the hardware asset state and substate based on specific fields on the catalog tasks.
The scenario is that when a user is getting offboarded, the associated assets will also be updated in the hardware table from "In use" to "In stock" or whatever is selected in the catalog task fields. If a user have 4 assets associated ( 2 computers and 2 communication device) then total 4 tasks are getting triggered. Accordingly the number of assets of the offboarded user is triggering that many number of tasks which is working. For each tasks, assigned to will pick one asset serial number and select the state to In stock or something else and substate to Available which will update the state and substate in the hardware table when the respective tasks will be closed.
I am trying to update the hardware table based on the field selections for all the respective tasks with respective assets selected on it . It is working for one task when I am testing this in the background script.
I would like to know how the code will loop all the tasks and update the state in hardware table based on the details selected in each generated tasks.
Please check the below code and help me how to achieve this for multiple tasks.
The below code I was trying to update 2 tasks with 2 computer assets of the user with same short description. Accordingly will do for the communication device tasks. The below code is only updating one task and not the other.
var getsc = new GlideAggregate('sc_task');
getsc.addQuery('request_item', '709a525583c74a105e6498747daad3c7');
getsc.addQuery('short_description' , "Offboarding - Computer");
getsc.addAggregate('COUNT');
getsc.query();
if (getsc.next()) {
codegs.print('Tasks: ' + getsc.getAggregate('COUNT')); var gl= new GlideRecord('sc_task') gl.addQuery('request_item', '709a525583c74a105e6498747daad3c7'); gl.addQuery('short_description' , "Offboarding - Local IT - Computer"); gl.query(); if (gl.next()){ for(var i=0; i<getsc.getAggregate('COUNT'); i++ ){if (gl.u_asset_details != ""){
codevar asset = gl.u_asset_details; var gr = new GlideRecord('alm_hardware'); gr.addQuery('sys_id', asset); gr.query(); if (gr.next()) { // for(var i=0; i<getsc.getAggregate('COUNT'); i++ ){ // gr.assigned_to = ''; gr.install_status = gl.u_asset_status; gr.substatus = gl.u_asset_substate; gr.update(); } - Assistant