Community
Showing results for 
Search instead for 
Do you mean 
Reply

Checkbox and IF statements

Copper Super Contributor
Posts: 478
Country: Australia

Checkbox and IF statements

Hi all

 

I am doing my next round of code, with a set of checkbox (Yes/No)

 

I want to be able run through each checkbox and if its checked run a bit of code to set up a new opportunity, and some new activities

 

However i can not work out the checkbox, I have tried different variations but this is the only thing that does not come up with an error message, unfortunetly it does not work as the code runs regardless of it its checked or not

 

if (c.Fields["CUST_ContactTable1_090144.CUST_ProdLife_065924792", true] != null)

 I have another peice of code that get the value and it appears to work fine so i have tried .ToString = "Yes" but that does not work

 

Any guidance would be great

 

Thanks


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Checkbox and IF statements

Try:

 

if (c.Fields["CUST_ContactTable1_090144.CUST_ProdLife​_065924792", true] != false)

 

Stan

 


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 478
Country: Australia

Re: Checkbox and IF statements

Thanks for your reply Stan, sorry i tried that one earlier it come sup with VS error of

Error 1 Operator '!=' cannot be applied to operands of type 'object' and 'bool' D:\Users\Jason\Documents\Visual Studio 2013\Projects\JDFPButtons\JDFPButton1\Class1.cs 210 17 JDFPButton1

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Copper Super Contributor
Posts: 478
Country: Australia

Re: Checkbox and IF statements

I find it rather strange as i have this

 

string LifeProd = c.Fields["CUST_ContactTable1_090144.CUST_ProdLife_065924792", true].ToString();

 Which works fine as it flows into another If statement creating a activity with the answer to this line as True or False in a string format

 

So i tried this

 

if (LifeProd = "True")

 

To me that should have worked.... nope


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Checkbox and IF statements

I suspect the reason is because it is a lower case "T" in "true".

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Checkbox and IF statements

I don't use "!=" having a mostly vb.net background but if that's the case then I would go with "<>" which does work in vb.net but might not work in cs.net.

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Copper Super Contributor
Posts: 478
Country: Australia

Re: Checkbox and IF statements

Thanks Stan for your replies but none work unfortunetly

when i convert it to a string it comes out with a capital T or F so dont know why that did not work

Still comes out with this error

Error 1 Cannot implicitly convert type 'string' to 'bool' D:\Users\Jason\Documents\Visual Studio 2013\Projects\JDFPButtons\JDFPButton1\Class1.cs 225 17 JDFPButton1

dont understand that given its in string form so i thought i would be able to compare it to a string

I will keep look

again thanks for the replies

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Copper Super Contributor
Posts: 478
Country: Australia

Re: Checkbox and IF statements

Just on the off chance

would i need any special reference to be added for this type of thing?

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 175
Country: USA

Re: Checkbox and IF statements

It appears to me that you aren't comparing apples to apples. After a quick test (using Intellisense) with a company, the Fields property is a MutableEntity.FieldCollection. That means, or at least should mean, that the object returned by it will be a MutableEntityFieldDescriptor. So, in short, it looks like you are trying to compare a FieldDescriptor object with a boolean value (object type vs. value type). That's never going to work.

 

I think you need another step in there. Can you declare a FieldDescriptor object, and assign it the object of c.Fields[] by converting your c.Fields[] object into a FieldDescriptor? Then, does comparing FieldDescriptor.GetValue(c) with your boolean value work?

 

I apologize if the wording is a bit weird.

Copper Super Contributor
Posts: 478
Country: Australia

Re: Checkbox and IF statements

Ok 50% of that i understood (but dont tell me let me try an work it out... got to lean something)

I understand that its basically saying i am comparing apples with a bannana, but thats the bit i dont understand to rip the value of the checkbox out as a string at the start of the code eg True or False this is put into the details of an activity all good works fine, so i dont understand why i cant compare that string to another string? why would "True" = "True" not work?

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6