What am I not seeing here?
It won’t allow a toggeled (desc) sort:
elements.OrderDate.text = “Order Date”
elements.OrderDate.bgcolor = “#FFFFFF”;
//var c = elements.OrderDate.bgcolor;
if ( elements.OrderDate.text == “Order Date(desc)” )
{
controller.sort(‘order_date desc’)
elements.OrderDate.text = “Order Date (desc)”
elements.OrderDate.bgcolor = ‘#ff0000’;
}
else
{
controller.sort(‘order_date asc’)
elements.OrderDate.text = “Order Date(asc)”
elements.OrderDate.bgcolor = ‘#66ccff’;
}
Also, what does this do?:
var c = elements.OrderDate.bgcolor;
Thanks in advance!
Providence
I think you may be confusing elements with dataproviders.
The statement:
elements.OrderDate.text = “Order Date”
only changes the name of the Text property of the field on the form. I think your intention is to test the value of the dataprovider that you attach to the field on the form. If so, you need to use a global or some other variable for OrderDate to be able to test it for a value.
var c = elements.OrderDate.bgcolor;
the statement loads the variable c with the current background color of the form element named OrderDate
I see that there is an image element in the background that is running the onAction method.
I believe I have it exactly as it is in the CRM, but it is only going in desc order.
I don’t understand what actually toggles it.
My version:
if ( elements.OrderDateText.text == “Order Date(desc)” )
{
controller.sort(‘order_date desc’)
elements.OrderDateText.text = “Order Date (desc)”
return elements.OrderDateText.bgcolor = ‘#ff0000’;
}
else
{
controller.sort(‘order_date asc’)
elements.OrderDateText.text = “Order Date(asc)”
return elements.OrderDateText.bgcolor = ‘#66ccff’;
}
And the CRM:
elements.headerCompanyImage.setImageURL(“media:///headerBlue150.png”)
if ( elements.headerCompanyText.text == “Company(asc)” )
{
controller.sort(‘company_name desc’)
elements.headerCompanyText.text = “Company(desc)”
elements.headerCompanyText.text
}
else
{
controller.sort(‘company_name asc’)
elements.headerCompanyText.text = “Company(asc)”
}
Sorry newbie!
It seems to me that if you want to toggle, you need to test for current status of “desc” sequence, and then sort into “asc” and vice versa?
They way I understand it is, I wasn’t resetting the text back after the first click.
elements.headerCompanyText.text
Is this correct?
Also, like FMP does the IF,THEN,ELSE statement only handle the first line of the statement? i.e., I’m not getting my color background on the labels to set.
I’m not sure what you mean by “resetting the text back”.
When I look at the fist two lines of your code:
if ( elements.OrderDateText.text == “Order Date(desc)” )
{
controller.sort(‘order_date desc’)
it tells me that you are testing to see if the text property of OrderDateText is set to descending sequence, and if it is, sort into descending sequence again. Don’t you want to test for current ascending sequence, and if found, sort into descending sequence and set the text property accordingly?
I think you probably do not need the return statement, unless you want to pass a parameter back to the method that calls this method. I assume that you want to set the background color for the various sequences
My suggestion would be the following:
if ( elements.OrderDateText.text == “Order Date(asc)” )
{
controller.sort(‘order_date desc’)
elements.OrderDateText.text = “Order Date (desc)”
elements.OrderDateText.bgcolor = ‘#ff0000’;
}
else
{
controller.sort(‘order_date asc’)
elements.OrderDateText.text = “Order Date(asc)”
elements.OrderDateText.bgcolor = ‘#66ccff’;
}
This way, even if the text value is not set to anything in particular, it will be sorted into ascensding sequence the first time the code is executed.
HTH
Dennis