Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

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.");
}

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

If local storage null not working

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.

Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

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?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

If local storage null not working

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.

Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

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.

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

If local storage null not working

Hi Anuj,

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

Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

If local storage null not working

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.

Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

If local storage null not working

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.

Return to “Issues”