Xrm.Page.getAttribute("").getValue() don't get actual value - dynamics-crm-2011

I have a custom entity in CRM 2011 with a Closure Code(drop down list) and Solution(multiple lines text) fields.
Is weird what is happening, and this is that the next sentence, is not getting the actual field value:
var detailsSet = Xrm.Page.getAttribute("aux_solution").getValue();
Why this could happen?

As explained in the comments, my problem was that the field wasn't taking the actual value because the focus was on it. Moving to another field before checking the values is how I solve this. I hope could help someone.

That is because the object model does not get refreshed data while you have focus on the field. If you want to get the value without having to click outside you need to use the good old document.getElementById .

If it is an option set, you should use eiter getSelectedOption() or getText()
so try
var detailsSet = Xrm.Page.getAttribute("aux_solution").getText();
For more details refer this

Related

xPages #DbLookup issue

I have this code in several repeat controls and computed values
#Unique(#DbLookup(database,view,key,columnnumber))
I can see that if "columnnumber" is a categorized column then DbLookup only return first Category.
Today my solution is create another view with this column Uncategorized, but this is bad solution for my customer, and more work for me.
Somebody knows if this is a bug? or is there another solution?
I have Lotus Domino 8.5.3 UP1 and same designer
Thanks a lot,
You can get the view entries this way:
var vc:NotesViewEntryCollection = database.getView("view").getAllEntriesByKey(key, true);
Then you can loop the collection with:
var ve:NotesViewEntry = vc.getFirstEntry();
ve = vc.getNextEntry();
In the loop, get the column value with:
ve.getColumnValues();
My understanding is that this will perform better than #DbLookup which - I believe - has similar code underlying it. Fastest way to loop a view is to use a ViewNavigator as Fredrik suggested:
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Fast_Retrieval_of_View_Data_Using_the_ViewNavigator_Cache
Try using #DbColumn instead or a viewnavigator.

session.evaluate and notesxspdocument

I have question regarding session.evaluate in SSJS. In a keyword document I have some #formula stored which does some conversion of data. Lets say this is would be:
#left(fieldname;2)
If the fieldname contained 'hello' this would result in 'he'. Nothing to fancy here. Now I would like to use this in an xpage.
I wrote a function called executeFormula(doc). I call this function from an action on a xpage. This xpage contains 1 notes document datasource. The function call is
executeFormula(datasource.getDocument(true))
Now for some reason the #formula is never calculated correctly. Do I need to save the document first before I can use session.evaluate(kwFormula,doc) or is the #formula wrong in some way?
p.s. I forgot to mention that this code is working inside a customvalidator
Without seeing the code for the executeFormula(doc) function it is very difficult to know exactly how session.evaluate is being called.
I would suggest taking the function out of the equasion for the moment and create a simple test page with the document source and a simple computed field with the session.evaluate in it so that you can see the result. Given your examples above the computed field would be something along the lines of
session.evaluate("#Left(fieldname;2)",xspDoc.getDocument(true));
Once you get acceptable results back then you can move it into your function and verify that it is working there also.
Don't forget that session.evaluate returns a vector so you may beed to do a .getFirstElement() on the returned value if it is not null.
If you're using it in a custom validator, the values posted from the browser/client haven't updated the data model (in your case, the document) yet. This happens after validation is successful.
I imagine it might work for some fields (e.g. fields that are updated after a successful refresh, or stored fields in an existing document).
Actually no need of mentioning the document, eg:- session.evaluate("#username") is enough.
For yours session.evaluate("#left('hello';2)") will work.,

Why the OnWorkflowItemChanged is different between List and document library?

I am doing a workflow for a document library. I put a OnWorkflowItemChanged, and I want to get the value of the column which is changed. I use the workflowProperties.Item["name"] and use the afterProperties. But when I use the workflowProperties.Item["column name"], I still got the original value. When I use the afterProperties, it's NULL.
Then I make another workflow that is the same as above for a list. I can use the workflowProperties.Item["column name"] to get the new value in OnWorkflowItemChanged.
Has anyone come across this problem before? Can you give me some help?
The question seems to mix up Item with ExtendedProperties. As to why a difference is seen on a List/Document Lib, it might have something to do with versionining or perhaps the internal serialization is different. Anyway, some of my experience is outline below. I hope it may be of use:
Use the GUID (as a Guid object, not a string) to access the Before / After ExtendedProperties field. Using the Display Name in the ExtendedProperties will not work. The documentation on it is wrong. You can use SPList.Fields to go from Display Name to Column ID (Guid).
I bind all "Before" to MyWhatever_PreviousProperties and all "After" to MyWhatever_Properties, only accessing MyWhatever_[Previous]Properties after the appropriate event(s)).

SPGridView, data and correct method of ensuring data is safe

I am using an SPGridView to present some data, and have enabled the filtering ability which works very well. Until you choose a particular item in the data to filter on...
The data item in question has an apostrophe in the string( e.g. "this is richards' string"), which causes the post-filter-application page load to die with the error:
Syntax error: Missing operand after 's' operator.
Obviously the data is not automatically made safe...
The data is in a datatable, and the SPGridView is fed using an objectdatasource using the datatable.
Whats the best, or correct, method to ensure the data is safe to use?
EDIT:
After much gnashing, I have found a partial answer but the question still remains.
The partial answer is - you can make the data safe for the filter code, but you then cannot make it look correct in the filter dropdown gui.
Adding BoundField.HtmlEncode = true; to the SPGridView definition does nothing.
Using HttpUtility.HtmlEncode on the string does nothing.
Manually replacing all apostrophes in the data with ampersand #39; on insertion into the DataTable allows the filter to work fine, and the data displays fine in the SPGridView, but it displays with the html replacement string in the filter dropdown, and not the apostrophe character. This is the partial solution, and isn't really usable as it creates a horrible filter string which is visible to the end user.
I am still to find a complete solution to this problem, save for removing offending characters from the data altogether, which isn't really a solution.
Regards
Richard
The apostrophe is a special character in the filters. Try replacing all instances of the "'" (one apostrophe) with "''" (double apostrophe).
Edit 09/01/2009
Ok, so it took me a lot longer than I thought to actually get this working. You should just need to add this to your web part code:
protected override void OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(gridDS.FilterExpression))
{
_gridDS.FilterExpression = string.Format(
_grid.FilteredDataSourcePropertyFormat,
_grid.FilterFieldValue.Replace("'", "''"),
_grid.FilterFieldName
);
}
base.OnPreRender(e);
}
Above, grid is your SPGridView and gridDS is of type ObjectDataSource which I believe is the only type that you will be able to get filtering to work with an SPGridView. Basically, I think what happens is that there is a bug in the Microsoft code and it doesn't really give you a chance to validate the filter value before it gets stuck in the FilterExpression. Using Reflector, I was able to figure out that the SPGridView really just sets the FilterExpression of your datasource. It does this using reflection and the value that you entered for your grid.FilteredDataSourcePropertyName property (I always see it being set to "FilterExpression" in all the examples).
Reference:
http://www.reversealchemy.net/2009/05/24/building-a-spgridview-control-part-2-filtering/

Set value of datetime field to null

So, I´ve got an issue that someone might have solved (or so I hope). I have a datetime field that I use in a contenttype (on a listtemplate) that has its own editform.
Here´s a walkthrough of what happens:
Adding a value to the datetime column and saving the updated value shows up (as expected).
Updating the datetime column and adding null (emptying out the value) via the editform. The value isn´t updated but instead showing the old value.
I did some experimenting with this and I came to the conclusion that if I add an eventreceiver and try to update the value there it doesn´t even enter the eventreceiver as a blank string (I had an idea that the value is as a blank string and sharepoint can´t parse that to a null datetime) which leads me to think that there´s an issue with the fieldcontrol that causes this. I also found this article on MSDN which seems to be around the same issue. And also, the datetime field in the contenttype isn´t required.
Any ideas or suggestions?
UPDATE:
Apparently this only happens when I use a custom editform. When I use one of built in listtemplates this works like a charm.
I've had similar issues with this in the past. It is indeed a known bug. One work around is to set the field to the min or max value of the type and check for this value wherever needed and do the appropriate conversions. Depending on your setup and use, you could create a trigger to convert min/max values to null and thus minimize the code required to handle such a work around.
After some deep investiongation I have found that the root of this problem is related to the fact that I was using XML node propagation between the columns in the list and the actual xml file. I had prevoiusly been struggling with this regarding stardard text fields and thought that I had taken care of the issue..apparently not. DateTime fields apparently will not get sent to the eventreceiver afterproperties if it is null as thus my code will not pick it up as a null value. I had to take case of that and add them to afterproperties if I can´t find them in afterproperties. I will make a blogpost series about these issues and post the links to this post shortly.
UPDATE:
I have now completed a blogpost about how I solved this issue. Feel free to check it out:
http://johanleino.wordpress.com/2009/08/24/node-demotion-does-not-work-with-blank-empty-values/

Resources