Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 6
Registered: ‎12-24-2012
My Device: BB 10 DevAlpha
My Carrier: Tata Docomo India

Can't find restore(Function Name) variable error in BB10 webworks

[ Edited ]

I am developing a contacts restore application that imports  contacts from a  vcard file. that the console shows can't find restore variable error while testing on a bb10 dev alpha . This is my res.js javascript file.The below code is to store a single line of a vcard file 

 

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();
console.log("entered function");
var 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);
}

 

and this is my html file

 

<div data-bb-type="screen" data-bb-style="fade">
<script type="text/javascript" src="res3.js"></script>
<div data-bb-type="button" data-bb-tytle="Getcontacts" onclick="restore();">Get Contacts</div>
</div>