1
votes

I have a dijit which displays a list of available contacts. Selected contacts then displayed in a view panel which was updating via a partial refresh until I added some code to check that duplicate contacts were not selected. Now the panel will not refresh. Any ideas?

Here's the SSJS which checks for duplciates. Sorry if I haven't explained this properlly or if there's a really simple solution to this 'problem' - total noob here.

var viewPanel=getComponent("viewPanel1");
var docIDs=viewPanel.getSelectedIds();

for(i=0 ; i  <  docIDs.length ; i++){

    var docId = docIDs[i];

    var doc:NotesDocument = database.getDocumentByID(docId);
        // Get Contact Details from document
    var FName = doc.getItemValueString("Org_Con_FirstName");
    var LName = doc.getItemValueString("Org_Con_SurName");
    var FullName = FName + " " + LName;
    var Phone = doc.getItemValueString("Org_Con_Phone");
    var Email = doc.getItemValueString("Org_Con_Email");
    var Unid = doc.getUniversalID();

    var checkView = database.getView("oppContacts");
    var checkCollection  = checkView.getAllDocumentsByKey(sessionScope.oppKey);
    var checkCount = checkCollection.getCount();
    var counter = 0;
    if(checkCount != 0 ){
        var checkDoc = checkCollection.getFirstDocument();
        while(checkDoc!=null){
            var checkEmail = checkDoc.getItemValueString("Email")
            if(checkEmail==Email) counter = counter + 1;
            var tempDoc = checkCollection.getNextDocument();
            checkDoc.recycle();
            checkDoc = tempDoc;
        }
    }


    if(counter==0){
        var oppContact = database.createDocument();

        oppContact.replaceItemValue("Form","oppContact");
        oppContact.appendItemValue("ContactName",FullName);
        oppContact.appendItemValue("Email", Email);
        oppContact.appendItemValue("Phone", Phone);
        oppContact.appendItemValue("FullContact",Unid);
        oppContact.appendItemValue("OpportunityKey", sessionScope.oppKey);

        oppContact.save();

    }

}
1
First thing I'd do is to add a try/catch block around that code to see if it doesn't throw any errors.Mark Leusink
It didn't throw any errors. The code is adding the contacts but I need to either do it twice or refresh the browser to update the view, and setting the button to full update doesn't work either :-(brtweed
I removed everything from 'var checkView = database' to 'if(counter)....' - partial refresh works. I give up :-(brtweed
I would check what the sessionScope.oppKey contains perhaps is nullFredrik Norling
I would also change this line if(checkEmail==Email) counter = counter + 1; so it would be with {}Fredrik Norling

1 Answers

1
votes

Try to return true at the end of your script, to go on with the server options that partially refresh your panel. If it runs into an error, then it will return false.

enter code here // at the beginning of code var bResult = false;

// inside if-statement : if (counter==0){ 
bResult = oppContact.save();

// at the end check bResult by setting sessionScope (using debug toolbar :-)
sessionScope.bResult = bResult;
// return true, hopefully
return bResult;

does your code yield a new document? hope this helps...