Automatically consuming a consumable via Request

genesislv
Kilo Contributor

I would like a consumable item be consumed and assigned automatically to the user when the hardware request (RITM) has been fulfilled and closed. Also I would like to reference that RITM record to that consumed record. Is there something built in OOB that I can configure to make this happen or does this require a bit of coding and customization on the catalog item?

Right now, we would have to manually consume the item once the RITM has been fulfilled and closed.

Thanks in advanced!

12 REPLIES 12

Community Alums
Not applicable

Hi Teri,


Tracing this through the Consume UI Action, you find it opens a UI Page called consume_a_consumable. This is what prompts for the quantity to consume and the user or asset to consume against. In the Processing script of that UI page, it does this to split out the consumed item:



var new_sys_id = new Consumables().splitForeground(consumable, qty, '10', '', asset, '', '', user);

}



Consumables here is a Script Include you can leverage in your code to do the work. The definition of splitForeground in the Script Include is:



splitForeground : function(sys_id, qty, status, substatus, asset, stockroom, location, assigned_to)



  • sys_id - the SysID of the In stock consumable from which you are consuming some quantity
  • qty - the quantity to consume
  • status - 10 is consumed
  • substatus - leave blank, consumed has no substate
  • asset - the asset to consume against - this becomes the parent of the consumed item
  • stockroom - leave blank - because this function is used in other places, such as splitting some quantity to a different location, it provides for other details
  • location - leave blank - same as stockroom
  • user - the user to which the consumed item should be associated - if it is associated to an asset, you can leave this blank


Good luck, Teri! I hope this helps!


bsweetser



Hi Ben, thank you so much for the guidance! I was able to create the RunScript in the Workflow to automatically consume the consumable upon deployment.



Thanks,


Teri


Hi Teri,



We were thinking of doing the same thing, I was wondering if you could share your RunScript?



Cheers,


Brendan


Hi Brendan, would be happy to help!



Here is my RunScript



var this_consumable = current.variables.ITAM_STD_Access_inventory_record;


//The this_consumable variable is a Reference variable used to select the consumable from the available stockrooms.


var this_qty = current.quantity;


var this_user = current.request.requested_for;



current.variables.ITAM_std_access_pull_from_stock = (" Qty "+ this_qty + "|" + this_consumable.getDisplayValue() );


//this line prints the value to a single line text variable on the Task form.



var new_sys_id = new Consumables().splitForeground(this_consumable, this_qty, '10', '', '', '', '', this_user);


//this is the script include that actually consumes and assigns to the user



Good luck!


Teri



Thanks for this Teri!