Get number field in sitecore index - webforms

I'd like to know how do you guys get a value from a number field through index search.
I'm using WebForms for my project currently I have this model
[IndexField("SomeNumber")]
int SomeNumber { get; set; }
and obviously a number field named "SomeNumber" in my sitecore item. But the thing is I only get 0 value for SomeNumber when I input a number on the field and a null when not. Note that I'm getting right values for my string fields so I'm not sure why the number field doesn't work right.
Thanks

Related

Why kendo mvc grid numeric integer column(numeric text box) is becoming zero , when I give decimal values to it

I am having kendo mvc grid and one of its column is numeric text box and it is of type integer , but when I try to give decimal values to numeric text box ,it is becoming zero , but it should get rounded to nearest integer or should not accept decimal values.
How can i do that , kindly anyone help me
CODE:
columns.Bound(c => c.Quantity).Title("Quantity").Width(100);
public int Quantity { get; set; }

Cannot find element with static id on page

i am new to cypress and here is my problem. I have a table that has a dynamic id for each entry. i want to have a function that gets the data from the table and checks if it contains a value i calculate. The problem i am facing is that when the cy.get tries to find the element and see if it contains a value it says it cant find element (if i check for attribute x it finds it) so i am thinking it might be because i declare the ID constant in the each function. Thank you for your time!
cy.get(tableElement).each(($element, index) = {
cy.log(`Table element is ${tableElement[index]}`)
someFormula = value1 + value2
cy.log(`Cypress element ${tableElement[index]} team is ${someFormula}`)
const realValueFromTable = `#id_${tableElement[index]}`
cy.log(realValueFromTable) //here i can see the full id #id_example1
cy.get(realValueFromTable).contains(someFormula)
//here it stays at get #id_example1 it should get the value from that id and compare it with the formula value

Lotus sorting view on orderdate does not work properly

I have created a view in which I also have a column which holds dates. This column can be sorted on ascending and descending. This is my column properties value:
But the problem is that the view does not sort the dates properly:
And here a screenshot of the orderdate field itself:
And here screenshot of the document with the orderdate that is out of order in the view:
Update
Some documents had the orderdate as text instead of date.. I create these documents through a java agent. The field orderdate I fill in like this:
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
But it is saved as text instead of date. Anyone knows why?
Problem was that orderdate field was set by a backend agent and this field was set with a string.
I know saved the current time as a DateTime object and now it works:
DateTime timenow = session.createDateTime("Today");
timenow.setNow();
docOrder.replaceItemValue("Orderdatum", timenow);
It's not clear to me why it's not working for you, but you can brute force it with something like this in the column formula
dateForSure := #TextToTime(OrderDatum);
#Text(#Year(dateForSure)) + "-" + #Text(#Month(dateForSure)) + "-" + #Text(#Day(dateForSure));
Also: your Java code saves a text value because the format() method of SimpleDateFormat returns a StringBuffer. The ReplaceItemValue method generates a text item when its input is a String or StringBuffer. Assuming your form defines OrderDatum as a Time/Date field, you can call Document.ComputeWithForm in your code to force it to convert the text item to a Time/Date. Another method - probably preferable given the potential side-effects of calling ComputeWithForm would be to create a DateTime object in your Java code and pass it to the ReplaceItemValue method instead.
It's because formatterDatumForField.format(currentDateForField) returns a String instead of a date/time value. Assuming that currentDateForField is a date/time value, you should change
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
to
docOrder.replaceItemValue("Orderdatum",currentDateForField);

MVC3 validation with data-annotation?

Is it possible to use a data-annotation attribute for dropdownlists to be valid, only if the user selects an option different from one with the value o (zero).
The option with value o (zero) is "Please Select an account", which is selected by default.
I used [Required] attribute to validate this dropdownlist, but it doesn't have any effect, because, how I said, by default the option with value o (zero)- "Please Select an account"- is selected.
Something like:
[Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
public int Value { get; set; }
Making a drop-down list required does not make sense. What you want required is that the user pick a value other than zero from the drop-down list. So what should be required is the SelectedAccount property. You should use the MVC helper method to bind the drop-down selected value to the SelectedAccount property:
#Html.DropdownListFor(m => m.SelectedAccount, new SelectList(Model.Accounts))
I am probably off on the syntax but you can look that up.
Now with regards to your other issue of ensuring that the value is not zero. Is the account number represented as a number or can it contain non-numeric characters? If it is a number then you should represent it as such in your code. And if it is truly a string, then the first value of your drop-down list should be an empty string and not zero.
If you decide that it is a number, then use the Range annotation to ensure that the value is greater than zero:
[Required]
[Range(1, Int32.MaxValue)]
public string SelectedAccountNumber {get;set;}
Hope that helps!

Change the Sequence of JqGrid Columns

I wanted to change the grid column sequence dynamically. For e.g. By default the grid will be loaded in LoginId, FirstName and LastName sequence. Based on some condition, I need to change the FirstName and LastName sequence.
Is there any way I can do this?
I tried doing like:
{name:'UserName',index:'UserName',width:82,sortable:false},
if(true)
{
{name:'FirstName',index:'FirstName',width:65,sortable:false},
{name:'LastName',index:'LastName',width:65,sortable:false},
}
else
{
{name:'LastName',index:'LastName',width:65,sortable:false},
{name:'FirstName',index:'FirstName',width:65,sortable:false},
}
but I could not get this work.
You can use remapColumns function to do this. In the documentation of the function you will find the example which seems to be wrong, because indexes in the permutation array seem to be 1-based and not 0-based. Try to use:
$("#list").remapColumns([1,3,2],true,false);
or
$("#list").remapColumns([1,3,2,4,5,6,7,8,9],true,false);
if you want to change the order of the second and third from the total 9 columns.

Resources