Post status update to IBM Connections using extlib - xpages

I am trying to post an update i.e. a status message to IBM Connections using the extlib.
I have used the extlib with connectionsLTPA endpoint which works really well for getting the communities list. However I wish to add functionality to update the users status.
So far I have tried using
<xp:this.data>
<xe:connectionsData var="connectionsData1"
endpoint="connections" serviceUrl="/profiles/atom/mv/theboard/entry/status.do?email=#{userBean.email}">
</xe:connectionsData>
</xp:this.data>
and then in the event handler
var sb = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<author><name>#{userBean.displayName}</name></author>" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
"<content type=\"html\">" +input + "</content>" +
"<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"status\" />"+
"</entry>\r\n";
var output = #{connectionsData1}.post(null, sb, "xml");
however this throws an error trying to call post on the binded data point.
Anybody able to point me in the right direction?
Thanks

I have found that implementing the sbt by doing the follwing:
<xp:button id="button2">
<xp:this.value>Update my status</xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial">
<xp:this.action><![CDATA[#{javascript:try {
var svc = new sbt.ConnectionsService("/profiles/atom/mv/theboard/entry/status.do?email=" +userBean.email);
var sb = new java.lang.StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<entry xmlns=\"http://www.w3.org/2005/Atom\">");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"entry\"/>");
sb.append("<category scheme=\"http://www.ibm.com/xmlns/prod/sn/message-type\" term=\"status\"></category>");
sb.append("<content type=\"text\">");
sb.append(getComponent("inputText1").getValue());
sb.append("</content>");
sb.append("</entry>");
var msg = svc.put(null, sb.toString(),"xml");
var msg = "updated users profile status";
#WarningMessage(msg)
} catch(e) {}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
The reason it wasn't working correctly is that the atom feed needed to be declared as an entry. This article in the connections doc for 2.5 http://publib.boulder.ibm.com/infocenter/ltscnnct/v2r0/index.jsp?topic=/com.ibm.connections.25.help/r_api_prof_update_photo.html explains the required parts of the xml atom document.

Related

Parameter in view.postScript

I visit this website to learn to use postscript in xpages. I follow the example to run the code and it runs property.
Then I begin to try other way. I use a computed field that use #DbLookup and a button that will use view.postScript to open xpage in a new window. When #DbLookup returns the value, that value will be the parameter in view.postScipt.
When I run the code, it returns error said Java method 'postScript(Array)' on java class 'com.ibm.xsp.component.UIViewRootEx2' not found
I get confuse about the error since it mentions it is java error and I don't have java code in the xpage.
I think the reason I get the error is the computed field returns more than one value.
However if I hard code values, it run fine
var myparam = "Test,Test2,Test3";
Or
var myparam = "Test"+"Test2"+"Test3";
Please find the code for your review please.(It includes the code that cause error, my attempts and the error message)
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:br></xp:br>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:
//use #DbLookup to find value, that value will be the parameter in postScript
var value = #DbLookup(#DbName(), "myView", keyword, 3);
return value;
}]]></xp:this.value>
</xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var myparam = getComponent("computedField1").getValue();//does not work
//var myparam = "Test,Test2,Test3"; //works
//var myparam = "Test"+"Test2"+"Test3"; //works
//var myparam = "Test"; //(original) works
var myurl = #LeftBack(context.getUrl(),"/") + "/testpostscript.xsp?id="+myparam;
//error occurs in this code
//Java method 'postScript(Array)' on java class 'com.ibm.xsp.component.UIViewRootEx2' not found
view.postScript("window.open('" + myurl + "')");}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
</xp:view>
I read this post and it seems different to my question.
When I search "postScript(Array) xpages" on the Internet, I don't find much information about it.
So my question is how to let view.postScript runs when the parameter contains multiple values?
Grateful for your advice please. Thank you.
You are right that the result of your #DbLookup returns more than one value (an array). That's why you see the underlying Java error that postScript(Array) is an unknown method. The postScript method expects a String as input.
I will suggest that you use #Implode() to join the result from the #DbLookup:
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<![CDATA[#{javascript:
var myparam = #Implode(getComponent("computedField1").getValue(); ",")
var myurl = #LeftBack(context.getUrl(),"/") + "/testpostscript.xsp?id="+myparam;
view.postScript("window.open('" + myurl + "')");}]]>
</xp:this.action>
</xp:eventHandler>
</xp:button>

XPages appendDocLink on Anonymous User Error

I am attempting to replace my 'traditional Notes' User Name and Password Request form with one designed in XPages, mainly because the #SendMail Formula no longer works with Firefox or Chrome.
Anonymous users are to complete an XPage Form, hit a submit button which then sends an email to our support team, which is to include a Doc Link back to an internal Notes form of the same document, - I don't want to change this internal form as there is lots of lotusscript programming associated with it for processing.
I have the XPage marked as Available to Public Access as is the form associated with it. I also have ComputeWithForm set to both.
I can access the data document components e.g. append to the mail rtf body using doc.getItemValueString("field"), but I cannot do the same with appendDocLink it appears to fail due to access problems. If I set Anonymous to Manager access in the ACL the Doc link is appended.
<xp:button value="Submit" id="button1" style="margin-top:50.0px">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="false" id="eventHandler1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="document1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript: if(document1.isNewNote()){document1.save();}
var doc:NotesDocument = document1.getDocument(true);
var receiverEmail = "Support Requests";
var requestor = "xyz#company.co.uk";
db = sessionAsSignerWithFullAccess.getCurrentDatabase();
var memo = db.createDocument()
memo.appendItemValue("Form","Memo");
memo.appendItemValue("Principal","Company#NotesDomain");
memo.appendItemValue("From",requestor);
memo.appendItemValue("INetFrom",requestor);
memo.appendItemValue("DisplaySent",requestor);
memo.appendItemValue("SMTPOriginator",requestor);
memo.appendItemValue("Subject","NEW: Name & Password Request for "+getComponent("reqCompany1").getValue());
var rtitem:NotesRichTextItem = memo.createRichTextItem("Body");
rtitem.addNewLine();
rtitem.appendText("A new Name & Password Request has been logged by "+getComponent("reqFirstName1").getValue()+" " + getComponent("reqSecondName1").getValue()+" of "+ getComponent("reqCompany1").getValue());
rtitem.addNewLine();
rtitem.appendText("Click the Doc link to action it. ");
rtitem.appendDocLink(doc);
memo.send(receiverEmail);}]]></xp:this.script>
</xp:executeScript>
<xp:openPage name="/UserNandPSubmitted.xsp"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
The following errors occur.
com.ibm.jscript.InterpretException: Script interpreter error, line=25, col=8: [TypeError] Exception occurred calling method NotesRichTextItem.appendDocLink(lotus.domino.local.Document)
null
NotesException: Notes error: You are not authorized to perform that operation
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
lotus.domino.local.RichTextItem.appendDocLink(Unknown Source)
Any help would be greatly appreciated.
Make sure Anonymous user can access the default view of the database - so make it accessible to public access users. appendDocLink() method requires this view in order to append doc link to RT item.

XPages: image onCclick needs 2 clicks to do what is expected

I have a custom control that contains 2 images: add and remove from favorites.
There is some code on the onCLick event of the image, and both images use a SSJS function to see if the current document is already in the favorites or not, in the visible property of each image.
All works well, execpt that I need to click twice on the image in order to see the changes in the UI. Both onClick events are set to FullUpdate (also tried partial update with the panel that contains the images).
I could move all the favorites logic into session scope variables, but I think this should work as is. I just don't understand why I need to click twice, as if the partial refresh doesn't do anything (though it is, as I see the reload Arrow in the browser!).
Can it be that the code takes too long to execute and the refresh doesn'T get the updated info???
Here's the custom control code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.resources>
<xp:script src="/AppUtils.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:image url="/favorites-add.png" id="image1"
alt="Add to Favorites" title="Add to Favorites">
<xp:this.rendered><![CDATA[#{javascript:!isInFavorites(document1.getDocument().getUniversalID(), userBean.canonicalName);
}]]></xp:this.rendered>
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:addToFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);}]]></xp:this.action>
</xp:eventHandler>
</xp:image>
<xp:image url="/favorites-remove.png" id="image2"
alt="Remove from Favorites" title="Remove from Favorites">
<xp:this.rendered><![CDATA[#{javascript:isInFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);
}]]></xp:this.rendered>
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:removeFromFavorites(document1.getDocument().getUniversalID(),userBean.canonicalName);}]]></xp:this.action>
</xp:eventHandler>
</xp:image>
</xp:view>
And here's the SSJS:
function addToFavorites(unid, userName) {
var newDoc:NotesDocument = database.createDocument();
newDoc.appendItemValue("Form","Favorite");
newDoc.appendItemValue("UserName", userName);
newDoc.appendItemValue("DocUNID", unid);
newDoc.save();
return;
}
function removeFromFavorites(unid, userName) {
var notesView:NotesView = database.getView("(lkpFavorites)");
var keys = new java.util.Vector();
keys.addElement(userName);
keys.addElement(unid);
var coll:NotesDocumentCollection = notesView.getAllDocumentsByKey(keys, true);
if(coll.getCount()==1) {
coll.getFirstDocument().remove(true);
}
return;
}
function isInFavorites(unid, userName) {
var notesView:NotesView = database.getView("(lkpFavorites)");
var keys = new java.util.Vector();
keys.addElement(userName);
keys.addElement(unid);
var coll:NotesDocumentCollection = notesView.getAllDocumentsByKey(keys, true);
if(coll.getCount()>0) {
return true;
} else {
return false;
}
}
I'd suggest you to put an xp:link around your image to cast the event code instead of using the evennts of the image directly.
OK, not sure what happened there but I manually edited the custom control's source to see wheter I had empty eventHandler as suggested by Oliver, and it started to work as expected. I am totally unsure of what I changed: to my knowledge, all I did was to add extra "returns" in the source view, to make it more readable... Christmas gift I guess.
All is good now. Thanks to all :)

Using view.postscript in xpages

I have a xpage that use view.postscript like this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:dojoModule name="dojox.widget.Toaster"></xp:dojoModule>
<xp:styleSheet href="/.ibmxspres/dojoroot/dojox/widget/Toaster/Toaster.css"></xp:styleSheet>
</xp:this.resources>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[var Toaster = function(id, msg, type, duration, pos) {
type = (type == null) ? "message" : type;
duration = (duration == null) ? "5000" : duration;
pos = (pos == null) ? "br-up" : pos;
var obj = dijit.byId(id);
obj.positionDirection = pos;
obj.setContent(msg, type, duration);
obj.show();
}]]></xp:this.value>
</xp:scriptBlock>
<xp:div id="toaster" themeId="toaster" dojoType="dojox.widget.Toaster"></xp:div>
<xp:button value="Toaster" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:view.postScript("Toaster('"+getComponent("toaster").getClientId(facesContext)+"', 'toaster message!')");}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
But when I click button,the toaster can't show.Why?
And I need a way to show the toaster called by ssjs function.
Thanks a lot.
As #Frantisek Kossuth said, you're re-submitting the page. When your refreshMode is complete it will re-render the page based on the server values. If you want to make client side changes and reflect them in your UI, you can't do a refresh of complete. Doing a partial refresh of the page on an element that won't change (like button1) should update your UI without rebuilding the page.
Similarly, why do you need this to be done through SSJS? Why not just use Client actions in your button activation? If this isn't part of a larger function call that you're not including, simply change the event code from Server to Client and call the Toaster function that way. This would also allow you to not have to submit anything, leaving submit="false" in your eventHandler to avoid unnecessary functionality.

Xpages #Dblookup does not work on server

I write a xpages.
detail: There are two combobox A,B. I use #Dbcolumn on combobox A to get option data from notesview and I will throw the choice I get from A to get second data for B.
the problem is: it work well on my localserver, but get no result on the server.
I'll be very appreciate for any suggestion, thanks you!!
code is on server side as follow:
var fd_AppChoice:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("fd_AppChoice");
var AppChoice=#Trim(fd_AppChoice.getValue());
var temp=new Array();
temp=#DbLookup("","(A)",AppChoice,2);
return temp;
That code doesn't look right - you don't have the server. And defining a variable doesn't fix its data type, so var temp=new Array(); is irrelevant. I also would rather bind the fd_AppChoice to a scope variable e.g. viewScope.appChoice, then your code get easier. Try this:
var appChoice = #Trim(viewScope.appChoice); // Use getComponent.getValue if you have to
var server = #DbName();
// if different server or nsf have = ["myserver","mydb.nsf"] or [#DbName()[0],"my.nsf"]
var result = #DbLookup(server,"(A)",appChoice,2);
return result || ["Sorry nothing here"]
That should work
I can't quite confirm this: in my case it works like a charm on my test server (didn't even try locally). Here's my code:
comboBox #1 reads its values from a categorized view of the same database:
<xp:comboBox id="comboBox1" value="#{viewScope.combo1}">
<xp:selectItems>
<xp:this.value>
<![CDATA[#{javascript:#DbColumn(#DbName(), "myView", 1);}]]>
</xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="panelC2">
</xp:eventHandler>
</xp:comboBox>
Observe that the combo's onchange event performs a partial update on a panel which is a container for comboBox #2 (could it be that this is missing in your case?)
To get through with this, here's the remainder: combo#2 gets its values array using a #DbLookup which is filtered by the value selected in combo#1, which now is stored in a viewScope variable (how couldn't I agree with Stephan here: using a scope-var make things much easier!):
<xp:panel id="panelC2">
<xp:comboBox id="comboBox2" value="#{viewScope.combo2}">
<xp:selectItems>
<xp:this.value>
<![CDATA[#{javascript:#DbLookup(#DbName(), "myView", viewScope.combo1, 5);}]]>
</xp:this.value>
</xp:selectItems>
</xp:comboBox>
</xp:panel>

Resources