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

If local storage null not working

This first image shows the local storage variables, specifically the scanned_code and outpan_item_name variables.
Image

This second image shows how the entire process begins. The scan button is pressed, which invokes the barcode_scanner service.
Image

This third image shows the mapping that occurs on success of the barcode scan. The text from the barcode scan is saved to the local storage "scanned_code"
Image

This fourth image shows the setup of the barcode_search_outpan (which runs the api rest to outpan to scan the barcode. This is initiated on success of the barcode_scanner service after the barcode mapping.
Image

This fifth image shows the mapping of the scanned_code to the api before the send.
Image

This sixth image shows the mapping that occurs after the success of the api call. the name field from the api response is mapped to outpan_item_name local storage variable.
Image

This last image shows the javascript that we have been discussing which is called after the success of the api call and after the previous mapping.
Image

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

If local storage null not working

Hi Anuj,

It seems your "barcode_search_outpan" does not trigger "success" event barcode not found.

Details: http://prntscr.com/5s8a4d/direct

Please try to move this code to "complete" event handler.

Regards.

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

If local storage null not working

I apologize for my late response, as I was out of town.

I have tried your suggestion and moved the javascript action to Complete... but it still does not work. If the barcode is found, then it displays the alert, however if not found, it does nothing.

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

If local storage null not working

could the problem be that the api is returning:

"name": null,

whenever the barcode isn't found? im still unable to figure this out.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

If local storage null not working

You can do something like this

  1. Have a local storage variable (or a global JS variable)
  2. Set it to zero in the before Send event (Before Send Event)
  3. Set it to 1 if successful (Success Event)
  4. Set it to 2 if unsuccessful (Error Event)
  5. In the Complete Event value read (1 or 2?) the value of the local storage variable (or the global JS variable) and do the needful. Perhaps when it's successful you may want to store the values to some LSV or JS variables so that you can access it if it was able to successfully complete.
Anuj Puri
Posts: 0
Joined: Wed Dec 31, 2014 4:24 pm

If local storage null not working

That won't work unfortunately, as i don't need this based on a successful event, but based on whether the barcode api returns a value for "name" or not. If the barcode isn't found, it returns "name": null; , which technically is still a successful event, meaning the value of the variable would change from 0 to 1.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

If local storage null not working

Then why don't you do a simple check for null, in your success event

if( value ) {
// You have something that's not null
}
else {
// Null Value
}
will evaluate to true if value is not:
• null
• undefined
• NaN
• empty string ("")
• 0
• false

You can even do this check in your complete event. Do a check firstly whether it has been successful and then do a null value check. That would be more robust cos your scan process can sometimes fail, and you may have previous values etc.

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

If local storage null not working

Same issue... This works if a name is returned. This shows "Outpan found the item". But if the name is not returned, this doesn't do anything. Here's the javascript code I tried:

var outpanname = Apperyio.storage.outpan_item_name.get();
if (outpanname)
{
alert("Outpan found the item.");
}
else
{
alert("Outpan did not find the item.");
Apperyio('enter_name_label').show();
}

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

If local storage null not working

That means that your success event is not being fired. Because if you go by the normal "If else" statement - one of them will have to execute. It is either this, or that...there is no third block for the If else to execute

That's why I did mention about having those global variables or local storage variable where you clear the value "Before Send"...then update different values based on success / error. Then in your complete event check for the global success /failure values ...and then do a null check...or check if length 0

Or everytime before you execute it set the value of the variable to where you store the scanned value to some 'funny' value or number...eg: 88888...then check do your final check to see if it is different (which means that a new value has been stored)

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

If local storage null not working

Remember that the complete event should fire irrespective of whether the scan was successful or it failed

Just a note:

The most common way of reading Local Storage Variables seems to be:

var outpanname = localStorage.getItem('outpan_item_name');

and not
Apperyio.storage.outpan_item_name.get();

even though it may / does work

Return to “Issues”