Page 1 of 4

If local storage null not working

Posted: Thu Jan 08, 2015 3:03 am
by Anuj Puri

Here is sample javascript that I'm trying to use. I'm sure there are cleaner, shorter ways to write this, but I can't get even this to work. I'm using a barcode scanner to scan an item and then send it via an API call to return what the barcode item is. The name that is returned for the item is then stored in a local storage called outpan_item_name. If there is no name returned (or null) then a message should be shown saying item not found. Else, the item is found. With the below code, if a name IS returned, then "Item found." is displayed. However, if the name is NOT returned, then for some reason "Item not found." is not displayed. Why is the if statement not working?

var outpanname = Apperyio.storage.outpan_item_name.get();
if (outpanname === null outpanname === "null" outpanname.length < 1)
{
alert("Item not found.");
}
else
{
alert("Item found.");
}


If local storage null not working

Posted: Thu Jan 08, 2015 3:07 am
by maxkatz

Add a console.log(...) to see what you are actually getting from local storage. The if-statement is actually working (just not as you would expect), one of the three conditions evaluates to true.


If local storage null not working

Posted: Thu Jan 08, 2015 3:15 am
by Anuj Puri

does console.log work on a mobile device (android)? I tried adding alert(outpanname.length); before the if statement, and that returns an alert when a name is returned, but doesn't do anything is there is no name returned. wouldn't the alert act the same way as the console.log?


If local storage null not working

Posted: Thu Jan 08, 2015 5:42 am
by Yurii Orishchuk

Hi Anuj,

Yes, you can use console.log code and see result(debug) in weinre debugger.

Please read more how to use it here:
http://devcenter.appery.io/documentat...

Regards.


If local storage null not working

Posted: Fri Jan 09, 2015 1:37 am
by Anuj Puri

Alright, so I used the console log through weinre. With a normal scan on a barcode that returns a result, the resources tab fills the local storage variable outpan_item_name with the name of the product (the result). With a barcode it can't find, it doesn't do anything (the variable remains hidden from the local files screen under resources. I looked at the console and here is what it shows:

App successfully registered with Appery.io Push service
processMessage failed: Error: TypeError: Cannot read property 'length' of undefined
processMessage failed: Stack: TypeError: Cannot read property 'length' of undefined
at file:///android_asset/www/startScreen.js:263:54
at Object.cordova.callbackFromNative (file:///android_asset/www/files/resources/lib/cordova.js:294:48)
at processMessage (file:///android_asset/www/files/resources/lib/cordova.js:1053:21)
at androidExec.processMessages (file:///android_asset/www/files/resources/lib/cordova.js:1090:13)
at instrumentedCode (http://debug.appery.io/target/target-...)
processMessage failed: Message: F07 PushNotification1133664932 sInvalid action
processMessage failed: Error: TypeError: Cannot read property 'length' of undefined
processMessage failed: Stack: TypeError: Cannot read property 'length' of undefined
at eval (eval at (file:///android_asset/www/files/resources/lib/jquery/jquery-2.1.1.js:330:5), :871:54)
at Object.cordova.callbackFromNative (file:///android_asset/www/files/resources/lib/cordova.js:294:48)
at processMessage (file:///android_asset/www/files/resources/lib/cordova.js:1053:21)
at androidExec.processMessages (file:///android_asset/www/files/resources/lib/cordova.js:1090:13)
at instrumentedCode (http://debug.appery.io/target/target-...)
processMessage failed: Message: F07 PushNotification1133664933 sInvalid action

How do I translate this into popping up the alert that the item was not found? I even tried creating a label instead of using alert and having the label show, but that didn't work either.


If local storage null not working

Posted: Fri Jan 09, 2015 9:42 am
by Ihor Didevych

Hi Anuj,

Could you try to use ( ... outpanname.length ) instead (... outpanname.length < 1)?


If local storage null not working

Posted: Fri Jan 09, 2015 11:40 am
by Anuj Puri

I remember trying that before and it not working. I just tried again and got essentially the same log console message:

App successfully registered with Appery.io Push service
processMessage failed: Error: TypeError: Cannot read property 'length' of undefined
processMessage failed: Stack: TypeError: Cannot read property 'length' of undefined
at file:///android_asset/www/startScreen.js:263:54
at Object.cordova.callbackFromNative (file:///android_asset/www/files/resources/lib/cordova.js:294:48)
at processMessage (file:///android_asset/www/files/resources/lib/cordova.js:1053:21)
at androidExec.processMessages (file:///android_asset/www/files/resources/lib/cordova.js:1090:13)
at instrumentedCode (http://debug.appery.io/target/target-...)
processMessage failed: Message: F07 PushNotification93613601 sInvalid action
processMessage failed: Error: TypeError: Cannot read property 'length' of undefined
processMessage failed: Stack: TypeError: Cannot read property 'length' of undefined
at eval (eval at (file:///android_asset/www/files/resources/lib/jquery/jquery-2.1.1.js:330:5), :870:54)
at Object.cordova.callbackFromNative (file:///android_asset/www/files/resources/lib/cordova.js:294:48)
at processMessage (file:///android_asset/www/files/resources/lib/cordova.js:1053:21)
at androidExec.processMessages (file:///android_asset/www/files/resources/lib/cordova.js:1090:13)
at instrumentedCode (http://debug.appery.io/target/target-...)
processMessage failed: Message: F07 PushNotification93613602 sInvalid action


If local storage null not working

Posted: Mon Jan 12, 2015 2:51 am
by Yurii Orishchuk

Hi Anuj,

Please try debug your code with following logs:

pre

var outpanname = Apperyio&#46;storage&#46;outpan_item_name&#46;get();

&#47;&#47;Alert current outpanname&#46;
alert("outpanname = '" + outpanname + "'");

if (outpanname === null outpanname === "null" outpanname&#46;length < 1)
{
alert("Item not found&#46;");
}
else
{
alert("Item found&#46;");
}

/pre

Then compare give alert with your real value.

If you have there always undefined/null - that means - you init this storage incorrectly.

Regards.


If local storage null not working

Posted: Mon Jan 12, 2015 11:08 pm
by Anuj Puri

If the barcode is is found, then it alerts me twice: first it states "outpanname = and then the name of the item" It then alerts saying item found.

If the barcode isn't found, it doesn't do anything. no alerts at all.


If local storage null not working

Posted: Tue Jan 13, 2015 4:47 am
by Yurii Orishchuk

Hi Anuj,

Please specify following information about your implementation:

  1. Show screen shot how do you set "outpan_item_name" storage.

  2. Where do you use this code(with alerts)?.

    Regards.