Page 3 of 6

Create or update database from array items

Posted: Tue May 12, 2015 3:05 am
by Yurii Orishchuk

Hi Mark,

Sure, you can pass there any value you need.

Regards.


Create or update database from array items

Posted: Wed May 13, 2015 4:38 am
by Mark7294305

Hi Yurii
when use that code the results returned is empty. if the value of producty is 6 and the value of stockqty is 5, I want 11 to be displayed


Create or update database from array items

Posted: Fri May 15, 2015 1:54 am
by Yurii Orishchuk

Hi Mark,

May be problem in string value of your parameters.

Please try to use following JS code:

pre

"Qty_in_Cup": (parseInt(productqty) + parseInt(stockqty))

/pre

Regards.


Create or update database from array items

Posted: Fri May 15, 2015 11:17 am
by Mark7294305

Hi Yurii
That code also failed. It also erases the value which was stored in the database


Create or update database from array items

Posted: Sat May 16, 2015 7:44 am
by Mark7294305

Hi Yurii
Please ignore. The code works ok


Create or update database from array items

Posted: Sat May 16, 2015 11:43 am
by Mark7294305

Hi Yurii
One last question ;-) How do I add a Math.ceil to the stockqty value. So for example

"Qty_in_Cup": (parseInt(productqty) + parseInt(stockqty) return Math.ceil)


Create or update database from array items

Posted: Sat May 16, 2015 12:53 pm
by Mark7294305

Hi Yurii
I have also worked out the Math.ceil command. But I have another problem. Some values are received as 0.65 for example and I need to round this value up to 1. If I use the Math.ceil command it returns the value 0. What command can I use to round any value under 1 up to 1?


Create or update database from array items

Posted: Sat May 16, 2015 1:33 pm
by Mark7294305

Hi Yurii
Please ignore. All working using a if statement ;-))


Create or update database from array items

Posted: Sun May 24, 2015 8:29 pm
by Mark7294305

Hi Yurii
I still have a slight problem with this. Here is my current server code.

****

var DB_id = "54ae8e1ce4b042777ffe572c";
var collectionName = "CupboardStore_Coll";
var productid = request.get("productid");
var newproductname = request.get("newproductname");
var productbarcode = request.get("productbarcode");
var deptName = request.get("deptName");
var shelfid = request.get("shelfid");

var productqty = request.get("ProductQty");
var itemName = request.get("itemName");
var Product_Desc = request.get("Product_Desc");

if (productqty < 1)

Code: Select all

{ productqty = 1 

}; 

var query = [] ;

try

{

// result = {};
var result = [];
var params = {};
params.criteria =

{

Code: Select all

//Barcode: productbarcode 
 ASDAcin: productbarcode 

};

Code: Select all

 query = Collection.query(DB_id,collectionName,params) ;  

if (query.length === 0)

Code: Select all

{ 

        Collection.createObject(DB_id, collectionName, { 

          "Barcode": productbarcode, "Product": newproductname, "Qty_in_Cup": productqty, "Qty_Max": (parseInt(productqty) + 1), "Consumed": 1, "Restock_Level": 0, "Restock_Flag": productqty, "Restock_Qty": 1, "ASDAcin": productbarcode, "deptName": deptName, "shelfid": shelfid, "Substitutions": false 
         }); 

} else{

Code: Select all

 for (var i=0; i < query.length; i++){ 
   var currentObject = query[i]; 

         Collection.updateObject(DB_id, collectionName, currentObject["_id"], { 

"Qty_in_Cup": parseInt(currentObject["Qty_in_Cup"]) + (parseInt(productqty))
, "Consumed": parseInt(currentObject["Qty_Max"]) - (parseInt(currentObject["Qty_in_Cup"]) + (parseInt(productqty))), "Restock_Qty": parseInt(currentObject["Qty_Max"]) - (parseInt(currentObject["Qty_in_Cup"]) + (parseInt(productqty))), "Restock_Flag": (parseInt(currentObject["Restock_Flag"]) + (parseInt(productqty))),
"deptName": deptName, "shelfid": shelfid, "Product_Desc": Product_Desc, "CrossOff_SL": false

Code: Select all

     }); 

 } 

 response.success(result); 

}

} catch (e)

{

Code: Select all

 response.success("message: " + e.message + "ncode: " + e.code); 

}

*****

When I upload the first set of products all works ok.

Image

when re upload the first set of products. The "Qty_in_Cup" Column in the database updates as required

Image

However If I add a new set of products. The columns in the database are emptied.

Image

How Can I fix this?


Create or update database from array items

Posted: Tue May 26, 2015 6:33 am
by Mark7294305

Can anyone else on the support team help me with this??