Assets Management

Hello,

I am new to Xwiki and programming overall.

I want to create an assets management tool for a manufacturing plant.

What I’d like the tool to do is, for example:

  1. Use app within minutes to store information about my inventory, including the quantity (kg) of parts.
  2. Create an app that allows users to use a certain quantity of elements in the inventory.
  3. Summarize the amount of material used from the inventory.

I have started working on this idea by creating objects (class=inventory) with a numerical property of weight and then trying to query the class property values. So far I have been able to list them, but not to create sums of property values.

I appreciate any guidance on this matter and any problems I might stumble on with this kind of approach.

Thank you!

I am trying to sum the property values of objects from a testClass.

The result of the velocity script includes boolean values I would not like to have on a table.

{{velocity}}
#set($xwql = "from doc.object(XWiki.testClass) as pc where doc.fullName <> 'XWiki.testTemplate'")
#set($results = $services.query.xwql($xwql).execute())
#set($list = [])
#foreach ($item in $results)
  #set($pc = $xwiki.getDocument($item))
  $list.add($pc.display("number"))
#end
$mathtool.getTotal($list)
{{/velocity}}

Any suggestions on how to avoid the problem?

You should use this instead

$list.add($pc.getValue("number"))

You can also compute the sum directly from the database query by “joining” the number property. See the examples from https://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module .

Thank you for the reply.

Your suggestion does give me the sum, but I am still stuck with the booleans that come from the java .add method.

Anyhow, I found a solution for by doing:

#set($sum=0)
#set($count=0)
#foreach ($item in $results)
  #set($pc = $xwiki.getDocument($item))
  #set($sum = $sum+$pc.getValue('number1'))
#end
$sum
{{/velocity}}

You can “capture” the value returned by add() before it is displayed by affecting the result to a temporary velocity variable using #set. By convention we use the $discard variable for this purpose.

An example:

#set ($discard = $list.add($pc.display("number")))
1 Like