0
votes

I am developing an app for blackberry 10 os using webworks framework.. when i run the following code in a bb10 dev alpha device, i get a console log of cant find restore variable.My html file contains a bbui button and on onclick the function restore is invoked. The javascript code is posted below..

        var text="FN: Mohammed;Shinoys\n";
        var a=new Array();

        a=["N","FN","NICKNAME","TEL;CELL",
           "TEL;TYPE=CELL","TEL;HOME","TEL;TYPE=HOME",
            "EMAIL;HOME","EMAIL;TYPE=HOME","EMAIL;WORK",
            "EMAIL;TYPE=WORK","ADR;HOME","ADR;TYPE=HOME",
            "LABEL;HOME","LABEL;TYPE=HOME","ADR;WORK",
            "ADR;TYPE=WORK","LABEL;WORK","LABEL;TYPE=WORK","NOTE","ORG","TITLE"];

        function restore()
        {
         var contacts = blackberry.pim.contacts;
        var contactAddress = contacts.ContactAddress;
        var contactField = contacts.ContactField;
        var name = new Object();
        var ename;
        var bb= new Object();
        var tt= new Object();
        var textarray=new Array();
        var arr=new Array();
        var s=new Array();
        var str,check,string;
        var textarray2=new Array();
        var newcontact = new Object();
        console.log("entered function");
        newcontact=contacts.create({name:{givenName:"Hello",familyName:"World"}});
        console.log("NEWCONTACT: " + newcontact.ContactName.givenName);

        for(var k=0;k<a.length;k++)
        {
            str=a[k];
            check=text.match(RegExp("^"+str+":","i"));
            if(check===null)
            continue;
        //alert(check);
            console.log(str);
            string=text.replace(RegExp("^"+str+":","i"),"");
            console.log("string"+string);

            switch(k)
            {case 0 : 
                        arr=string.split(";");
                        console.log("name "+arr);
                        newcontact.ContactName.familyName=arr[0];
                        newcontact.ContactName.givenName=arr[1];
                        break;
             case 1 :   console.log("ASDADAD");
                        newcontact.ContactName.formatted=string;
                        console.log("FULL name "+arr);
                        ename=string;
                        break;
             case 2 : newcontact.ContactName.phoneticGivenName=string;
                        break;
             case 3 : 
                        case 4 : tt={type:contactField.MOBILE,value:string};
                        newcontact.phoneNumbers[newcontact.phoneNumbers.length]=tt;
                        break;
              case 5 :
              case 6 : tt={type:contactField.HOME,value:string};
                        newcontact.phoneNumbers[newcontact.phoneNumbers.length]=tt;
                        break;
              case 7 : 
              case 8 :  tt={type:contactField.HOME,value:string};
                        newcontact.emails[newcontact.emails.length]=tt;
                        break;
              case 9 : 
              case 10 : tt={type:contactField.WORK , value:string};
                        newcontact.emails[newcontact.emails.length]=tt;
                        break;
              case 11 : 
              case 12 : s=string.split(";");
                        bb={type:contactAddress.HOME,streetAddress:s[2],locality:s[3],region:s[4],postalCode:s[5],country:s[6]};
                        newcontact.addresses[newcontact.addresses.length]=bb;
                        break;
              case 13 : 
              case 14 : if(newcontact.addresses[0].type===contactAddress.HOME)
                        newcontact.addresses[0].formatted=string;
                        if(newcontact.addresses[1].type===contactAddress.HOME)
                        newcontact.addresses[1].formatted=string;
                        break;
              case 15 : 
              case 16 : s=string.split(";");
                        bb={type:contactAddress.HOME,streetAddress:s[2],locality:s[3],region:s[4],postalCode:s[5],country:s[6]};
                        newcontact.addresses[newcontact.addresses.length]=bb;
                        break;
              case 17 : 
              case 18 :if(newcontact.addresses[0].type===contactAddress.WORK)
                        newcontact.addresses[0].formatted=string;
                        if(newcontact.addresses[1].type===contactAddress.WORK)
                        newcontact.addresses[1].formatted=string;
                        break;
              case 19 :newcontact.note=string;
                        break;
              case 20 :newcontact.organizations[0]={name:string};
                        str=a[k+1];
                        check=text.match(RegExp("^"+str,"i"));
                        if(check!==null)
                        {string=text.replace("^"+str+":","");
                        newcontact.organizations[0]={title:string};
                        }
                        break;
            }

        } 
           newcontact.save(onSaveSuccess,onSaveError);
        }

        function onSaveSuccess(contact) {
           alert("Contact saved: " + contact.name.givenName);
        }
        function onSaveError(error) {
           alert("Contact : save failed: " + error.code);
        }

Any help is appreciated. Regards shinoys222

1
Is there a simpler case you might be able to post? That piece of code is very difficult to follow. Some suggestions: 1. keep the code example concise and clean 2. post only that piece of code which is required to understand your question 3. add your console log's error output 4. provide any additional details pertaining to the error; for example, were you able to see this error in a device emulator, or only in the device, etc. Usually, the more detail and the cleaner the code example, the better the chance of getting an answer :)zealoushacker

1 Answers

0
votes

From the description of the problem, if the page cannot find the restore function, then that means this JavaScript code is not being loaded correctly. Recommend you check to make sure that you are properly referencing the JS file from your screen, like this:

<div data-bb-type="screen" data-bb-indicator="true">
    <script id="myJS" src="js/my.js"></script>

</div>