Hyperlink in Post entity's textfield - dynamics-crm-2011

I'm creating a Post entity (Activity feed entity) within my custom C# code and I need to be able to add a hyperlink into its text field.
Creating a post entity
Entity post = new Entity();
post.LogicalName = "post";
I could simply write something like
post["text"] = "http://www.google.com"
and it would work as a hyperlink. I think there's jQuery (out of a box?) that handles formatting in that case.
But in my case I'd like to add a hyperlink with a custom title. Something similar to
Click
Is there a supported way to do this or do I need to write my own client side script for formatting purposes?

For your text box content to work as a hyperlink, the Format of the Textbox needs to be URL. If you can set the format of your textbox, then any text that you put in there ,provided it follows the rules of hyperlink, it will be displayed as one.
Are you creating the attribute, or is it an existing one that you're trying to fiddle with? If it's an existing one, you need to write your own javascript to render it on the form as a hyperlink; and this would be unsupported.

you can use hyperlink with custom title like this:
string link = "<a onclick='window.open(" + "http://localhost:49944/Default.aspx? surveyresponseid=" + SurveyResponseId.ToString() + "); ' href='" + "http://localhost:49944/Default.aspx?surveyresponseid=" + SurveyResponseId.ToString() + "' target='_blank' >click this</a>";
post["text"] = link;

Related

Tracking document content changes

I'm trying to track the history of field values that are displayed in computed field as HTML. So far I got this:
var x = document1.getItemValue("category");
var html = "<table>";
for (i = 0 ; i < x.size(); i++){
html= html + "<tr><td>" + x + "</td></tr>";
html = html + "<tr><td>" + session.getEffectiveUserName() + "</td></tr>";
}
html = html + "</table>";
The code works ok, I get the value that I need and it gets displayed and if I edit the current document, the value changes via partial update that I have attached to the save button, but that's not the problem. The problem that I have is with saving it. I thought of creating an array and adding the value that changed but it will reset everything because of the script. Any suggestions how I can save that value or add it to the field? I was using Append ToTextList in forms, is there any way how to achieve that functionality in Xpages?
You can add a new value in a field in the querySave of the DominoDocument in XPages:
var x = document1.getItemValue("category");
x.add(myNewValue);
document1.replaceItemValue("category", x);
Chris Toohey just posted a blog article that seems to be what you're looking for.
http://www.dominoguru.com/page.xsp?id=thoughts_on_future_proofing_notesdata_for_application_development.html

pentaho modify and print a parameter while exporting to excel

I use pentaho report designer. I have got businessdate parameter in my prpt file. This has the value of the date range which is used to filter the sql query. I am able to handle and modify it while exporting to html however I have a problem in exporting to excel.
The date range comes in the formats below:
- BETWEEN {d '2014-01-01'} AND {d '2014-01-31'}
- IN ({d '2014-01-14'},{d '2014-01-15'}, {d '2014-01-19'} ,{d '2014-01-20'},{d '2014-01-21'})
I like to find out max and min date and display it. However in this case with excel, I am happy with displaying them separated with commas like shown below.
- 2014-01-01, 2014-01-31
- 2014-01-14, 2014-01-15, 2014-01-19, 2014-01-20, 2014-01-21
If I use the basic formula show below, it works in in excel but it does not work when I apply it to excel - formula section of the businessDate element in pentaho report designer.
=TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B4,"{d '",""), "BETWEEN", ""), "IN", ""),"'}",", "), " AND ", ""),")",""),"(",))
It does not have to be this way. I am happy with any method suggested to format this raw date range before printing to excel.
Thank you in advance.
After wasting a lot of time, I have found a way which works for all export types. As I said in my question, I was modifying date for html print by using "Structure Tab" --> Select "Master Report" --> "Attributes" Tab --> html -> "append-header" attribute.
<script type="text/javascript">
function init() {
var tableList = document.getElementsByTagName("table");
var businessDate = document.getElementById("businessDatePeriodSelected");
businessDate.innerHTML = businessDate.innerHTML+"testDateModified";
}
window.onload = init;
</script>
This piece of code does the job. However just for html. I needed to come up with something new. I was looking for a solution for excel and pdf exports as well.
HERE IS THE SOLUTION:
Click on "Data" tab next to the "Structure" tab on the right top side. You will see "Functions" in the tree. Right click and hit "Add functions". Select "Script" -->"Bean-Scripting Framework (BSF)". Select function created under Functions. Give it a name and add the code below to the "Expression" section. [This does not need a starting or ending tag]
/* businessdate is one of my parameters that I like to display on the report.
dataRow is automatically recognized by the interpreter which can be used for calling parameter values. It seems like came out of nowhere.*/
String value = dataRow.get("businessdate");
value= value.replaceAll("[^0-9\\-\\{\\}]", "");
value= value.replaceAll("[\\{]", ""); // replace all {
value= value.replaceAll("[\\}]", ","); // replace all }
value= value.substring(0, value.length()-1);
String[] dateArr = value.split(",");
return dateArr[0] +" - "+dateArr[dateArr.length-1];
The last thing you need to do is drag and drop your function somewhere suitable on your report. It will locate a textbox which will display the modified businessdate.
If you like to print a parameter on your pentaho report, this does the job for all exports (html, pdf and excel). You can also modify it before printing. This link pretty helpful as the syntax is slightly different at some points.
good luck.

XPages Extension Library Dialog control and updating "parent" document

I have an XPage with a Dialog control from the Extension Library.
The dialog works fine -- opens, does what it needs to do, however, when I try to update the "parent" document, it does not work.
I have the XPage data source as Domino Document called document1. I added this after reading:
When I save a document from an extension library dialog box some values are blank
<xp:this.data>
<xp:dominoDocument var="document1" formName="speakerReq"></xp:dominoDocument
</xp:this.data>
On the dialog control, I have a Search button which calls a servlet and returns JSON that is parsed and built into an HTML table. The first cell is a link which calls a function from a client side JavaScript library when it is clicked. The function is to update the "parent" document with values from the returned JSON as well as close the dialog.
It can call the function when I test with just an alert() statement in that function, however, when I try to update the "parent" document, it does not recognize that.
I have tried to pass the "document1" object but once I get to the dialog, it says it does not exist, so the link is failing.
Here is the code snippet where the link is built:
// Let's build the row...
cell = document.createElement("td");
resultLink = document.createElement("a");
resultLink.setAttribute("class", "linkText");
resultLink.setAttribute("href", "#");
resultLink.setAttribute("onclick", "javascript:updateDocument(document1, '" + bpName + "', '" + bpEmail + "', '" + bpPhone + "', '" + bpTitle + "', '" + bpCountry + "', '" + bpLoc + "');");
resultLink.appendChild(document.createTextNode(bpName));
cell.appendChild(resultLink);
row.appendChild(cell);
How do I get a handle on the document1 object on the client side so I can update those fields on the "parent" document as well as close the dialog?
Code:
function updateDocument(doc, name, email, phone, job, country, location) {
var thisField;
// Need to update the document with the selected values...
thisField = doc.getElementById("#{id:sr_Name1}");
thisField.value = name;
thisField = doc.getElementById("#{id:sr_Title1}");
thisField.value = email;
thisField = doc.getElementById("#{id:sr_Phone1}");
thisField.value = phone;
thisField = doc.getElementById("#{id:sr_Email1}");
thisField.value = job;
thisField = doc.getElementById("#{id:sr_Location1}");
thisField.value = location + " - " + country;
}
Thanks!
Seems you are mixing CSJS and SSJS up. The code snippet runs in the browser, but you try to execute server side code. This can't work. You need to post back your data to the server and handle the data there. The XPages Wiki has some ideas you might find useful.
Clarification:
Rule of thumb: anything that lands as JavaScript in your browser cannot have SSJS in it. So you can use anything DOM, but NO session, database, document1 etc. SSJS libraries are invisible to CSJS, so you can't call these methods. You can have a button in your page where you define both CSJS and SSJS. The client side would execute first and then do a refresh (partial or full).
Also your code above: getElementById is CSJS -> can't use that in a SSJS, while doc is as NotesDocumentDatasource -> doesn't have getElementById.
Furthermore: there is no "parent" element. The dialogbox is just another part of the local DOM (this is not NotesUIWorkspace.dialogbox). Check the XPagesWiki for samples

Adding content control throws an exception dynamically

I am fairly new to Word Addin development. Fortunately I was able to do almost everything but stuck at some simple issue I belive.
I want to insert plain text controls dynamically at the selected range. For this I am using the following:
currentDocument = application.ActiveDocument;
foreach(var field in myFieldsList)
{
Microsoft.Office.Interop.Word.Range rng = currentDocument.ActiveWindow.Selection.Range;
object oRng = rng;
var contentControlPlain = application.ActiveDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref oRng);
contentControlPlain.Tag = formField.FormFieldId.ToString();
contentControlPlain.SetPlaceholderText(null, null, " <" + formField.FormFieldName + "> ");
contentControlPlain.LockContentControl = (formField.TypeName.Trim() == "Blank");
}
Code seems to be working fine but when I try to insert the second field it complains saying:
This method or property is not available because the current selection partially covers a plain text content control.
I understand that addin is trying to insert next content control into the previously inserted plain text control. But I tried giving some other range and could not fix it.
Any help is greatly appreciated.
Thanks.
After adding every content control use
Application.Selection.Start = lastControl.Range.End+1

How do I filter a dojo grid on an xpage?

How do we filter the dojo grid (extlib component) that gets its data from the REST service component? I have the grid loaded with data from the view correctly from the REST service component. I also have on the xpage a dropdown where users can select a value that's a dbcolumn of one of the columns in the same view. I've tried setting the REST service keys value to viewScope.filterCat01 (which is the variable for the combo box), and I've also tried setting the filter in a button (BY is the field/column name) but nothing seems to filter it. Any ideas? In the button when I check grid properties, it does work, so I know the grid object is valid - but the filter just doesn't seem to be doing anything. I've also tried doing a grid._refresh() as well as setting the Keys in the REST service component with no luck. Is there a special way to trigger the filter?
var filterValue = XSP.getElementById("#{id:comboBox2}").value;
var grid = dijit.byId("#{id:djxDataGrid1}");
grid.filter({ By: filterValue});
This is definitely one of those things that you need to piece together a thousand cryptic clues to work it out (Domino - never!). Anyway, I had to work this one out last year. Here's an example 'search' button:
var searchText = dojo.byId('#{id:searchText}').value.replace(/"/g, '|"');
if (searchText) {
var ftSearchText = '[Title] CONTAINS "' + searchText + '" OR [Description] CONTAINS "' + searchText + '" OR [URL] CONTAINS "' + searchText + '"';
dijit.byId('#{id:grid}').filter('?search=(' + ftSearchText + ')', false);
} else {
dojo.byId('#{id:reset}').click();
}
As you can see, it's doing an ft search when a filter is applied. The key is to put "?search=" on to the beginning of the filter string.
and here's the 'reset' button example:
dojo.byId('#{id:searchText}').value="";
var grid = dijit.byId('#{id:grid}');
grid.filter("",true);
grid.store.close();
grid._refresh();
This was developed with 8.5.2. There might be some cleaner ways to do things in 8.5.3 with dojo 1.6.1.
Enjoy!

Resources