Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-2009, 01:51 PM
Junior Member
 
Posts: 9
Exclamation Create contact group via zimlet - HELP!

I am trying to create a contact group through a zimlet... If you take a look at my code below, you can see what I'm trying to accomplish. Below my code snippet you will find a the xml packet that is getting transmitted to the server (obtained using firebug and breakpoints).

Any advise would be GREATLY appreciated!!!

-------- ZIMLET CODE --------------

// Add a new group contact object...

// set up a BatchRequest for all contacts that need to be added... (Even though in this case it is only 1)

var soapDoc = null;
soapDoc = AjxSoapDoc.create("BatchRequest", "urn:zimbra");
soapDoc.setMethodAttribute("onerror", "continue");

var createContactReq = soapDoc.set("CreateContactRequest");
createContactReq.setAttribute("xmlns", "urn:zimbraMail");
var doc = soapDoc.getDoc();
var cn = doc.createElement("cn");
createContactReq.appendChild(cn);

// add nickname
var fn = doc.createElement("a");
fn.setAttribute("n", 'nickname');
fn.appendChild(doc.createTextNode(document.getElem entById('svsuNewGroup').value));
cn.appendChild(fn);

// add type
var ln = doc.createElement("a");
ln.setAttribute("n", 'type');
ln.appendChild(doc.createTextNode('group'));
cn.appendChild(ln);

// add dlist
var dl = doc.createElement("a");
dl.setAttribute("n", 'dlist');
dl.appendChild(doc.createTextNode('teststu@svsu.ed u'));
cn.appendChild(dl);

if (soapDoc) {
// finally, send the BatchRequest to the server
var respCallback = new AjxCallback(this, this._handleResponseCreate);
appCtxt.getAppController().sendRequest({soapDoc:so apDoc, asyncMode:true, callback:respCallback});
} else {
this._questionDialog.popdown();
}


-------- XML Call ---------

<BatchRequest xmlns="urn:zimbra" onerror="continue"><CreateContactRequest xmlns=""><cn><a n="nickname">def</a><a n="type">group</a><a n="dlist">tjpatter@svsu.edu</a></cn></CreateContactRequest></BatchRequest>
Reply With Quote
  #2 (permalink)  
Old 07-17-2009, 03:04 AM
Zimlet Guru & Moderator
 
Posts: 265
Default

Hi,

Here is some example code that work .
It create a contact group "test" with "john doe" and "xxx" :
Code:
	var soapDoc = AjxSoapDoc.create("CreateContactRequest", "urn:zimbraMail");
	var cn = soapDoc.set("cn");

	var fileAs = soapDoc.set("a", "8:test", cn);
	fileAs.setAttribute("n", "fileAs");

	var nickname = soapDoc.set("a", "test", cn);
	nickname.setAttribute("n", "nickname");

	var dlist = soapDoc.set("a", "\"john doe\" <foo@bar.com>, \"xxx\" <xxx@xxx.com>", cn);
	dlist.setAttribute("n", "dlist");
	
	var type = soapDoc.set("a", "group", cn);
	type.setAttribute("n", "type");

	var command = new ZmCsfeCommand();
	var response = command.invoke({soapDoc: soapDoc});
Reply With Quote
  #3 (permalink)  
Old 07-17-2009, 05:44 AM
Junior Member
 
Posts: 9
Default Thanks!

That code block worked great! I kind of figured it had something to do with how I was building the XML SoapDoc.

One additional question arises now... Is there a way to automatically refresh the contacts list without having a user to log off then log back on to see any new contact groups once the above code has executed?

Thanks again for all of your help! I will see if I can get permission to post our finished zimlet once complete.
Reply With Quote
  #4 (permalink)  
Old 07-17-2009, 09:13 AM
Zimlet Guru & Moderator
 
Posts: 265
Default

You shouldn't need to refresh anything.
When I tested the code block, the group added was visible immediately in the "Contacts" folder.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.