Community
Showing results for 
Search instead for 
Do you mean 
Reply

Opportunity Field Values - USER7

Accepted Solution Solved
Copper Super Contributor
Posts: 478
Country: Australia
Accepted Solution

Opportunity Field Values - USER7

Hi all

 

Can any one tell me why this code will not work,l i get an error saying that Act has had an error please close the program

 

I have tested the line by line and it appears it the following lines when the // are removed

 

                //object ob1 = mefd.GetValue(cOpp);

                //string str1 = mefd.GetValue(cOpp).ToString();

The code it launched when the opportunity detailed view is loaded and i am trying to get the value of User7, everything else appears to work even when i set "str1" manually

 

 

            if (viewName == "Act.UI.IOpportunityDetailView")
            {

                // Function to return the name of current layout
                // Act.UI.LayoutDesigner.LayoutFileInfo InfoLayout1;
                // InfoLayout1 = oApp.UILayoutDesignerManager.GetCurrentLayout(Act.UI.LayoutDesigner.LayoutType.opportunity);

                // Get Current Opportunity
                Opportunity cOpp = oApp.ApplicationState.CurrentOpportunity;

                MutableEntityFieldDescriptor mefd = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.User7);
                //object ob1 = mefd.GetValue(cOpp);

                //string str1 = mefd.GetValue(cOpp).ToString();
                string str1 = "Investment";

                MessageBox.Show("" + str1 + "\n\n" + mefd + "", oApp.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);


                if (str1 == "Investment")
                {

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

Accepted Solutions
Solution
Accepted by topic author JasonD
‎01-03-2016 10:16 PM
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Opportunity Field Values - USER7

Based on your code it would be something like:

 

oApp.CurrentOpportunityChanged -= oApp_CurrentOpportunityChanged;

 

at the beginning of the routine and:

 

oAppCurrentOpportunityChanged += oApp_CurrentOpportunityChanged;

 

just before the end of the routine.  You need to make sure that the second one runs if there is a problem with your routine so you would want to put a try...catch...finally in the routine.

 

Basically the try says "try this" and "catch" any error messages and "finally" do this.  So the "finally" will always execute adding your event handler back in.

 

Something like this:

 

       void oApp_CurrentOpportunityChanged(object sender, EventArgs e)
        {
 try
 {
            oApp.CurrentOpportunityChanged -= App_CurrentOpportunityChanged;
            string viewName = oApp.CurrentViewName;
            // Returns
            // Act.UI.IOpportunityDetailView
            // Act.UI.IOpportunityListView
            // Act.UI.IOpportunityView
            // Act.UI.ICompanyDetailView
            // Act.UI.ICompanyListView
            // Act.UI.ICompanyView
            // Act.UI.IContactDetailView
            // Act.UI.IContactListView
            // Act.UI.IContactView
            // Act.UI.IGroupDetailView
            // Act.UI.IGroupListView
            // Act.UI.IGroupView
 
            if (viewName == "Act.UI.IOpportunityDetailView")
            {
 
                // Function to return the name of current layout
                Act.UI.LayoutDesigner.LayoutFileInfo InfoLayout1;
                InfoLayout1 = oApp.UILayoutDesignerManager.GetCurrentLayout(Act.UI.LayoutDesigner.LayoutType.opportunity);
               
                string cLayout = InfoLayout1.ToString();
                string lstr1 = "";
 
                if (cLayout == "Basic Opportunity Layout - 1024x768.oly") lstr1 = "Default";
                if (cLayout == "JDFP Opportunity Layout 1.oly") lstr1 = "Investment";
                if (cLayout == "JDFP Opportunity Layout 2.oly") lstr1 = "Superannuation";
                if (cLayout == "JDFP Opportunity Layout 3.oly") lstr1 = "Insurance";
 
                string str1 = "";
 
                // Get Current Opportunity
                Opportunity cOpp = oApp.ApplicationState.CurrentOpportunity;
 
                MutableEntityFieldDescriptor mefd = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.User7);
                object oStr1 = mefd.GetValue(cOpp);
                if (oStr1 != null) str1 = oStr1.ToString();
 
                MessageBox.Show("" + str1 + "\n\n" + mefd + "", oApp.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (lstr1 != str1)
                {
                    if (str1 == "Investment")
                    {
 
                        // Creates and obtains list of all current Opportunity layouts available
                        Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                        InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                        // Returns
                        // InfoLayout 0 Returns "Basic Opportunity Layout - 1024x768.oly" - Default
                        // InfoLayout 1 Returns "Basic Opportunity Layout - 1366x768.oly"
                        // InfoLayout 2 Returns "Basic Opportunity Layout - 1920x1080.oly"
                        // InfoLayout 3 Returns "Basic Opportunity Layout - 800x600.oly"
                        // InfoLayout 4 Returns "JDFP Opportunity Layout 1.oly" - Investment
                        // InfoLayout 5 Returns "JDFP Opportunity Layout 2.oly" - Superannuation
                        // InfoLayout 6 Returns "JDFP Opportunity Layout 3.oly" - Insurance
 
                        oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[4]);
 
                    }
                    else
                    {
                        if (str1 == "Superannuation")
                        {
                            Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                            InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                            oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[5]);
                        }
                        else
                        {
                            if (str1 == "Insurance")
                            {
                                Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                                InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                                oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[6]);
                            }
                            else
                            {
                                Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                                InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                                oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[0]);
                            }
                            // End Insurance
                        }
                        // End Superannuation
                    }
                    // End Investment
                }
                else
                {
                    //Nothing
                }
                // End of Opportunity View
            }
        }
        catch (Exception e)
        {
            Messagebox.Show("{0} Exception caught.", e);
        }
        finally
        {
 oAppCurrentOpportunityChanged += oApp_CurrentOpportunityChanged;
        }
 }

 


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!

View solution in original post


All Replies
Copper Elite Contributor
Posts: 82
Country: Canada

Re: Opportunity Field Values - USER7

Did you check the Act Log viewer to find out why Act crashed?

 

I'd also check to make sure mefd is not null before calling any methods on it, and also "mefd.GetValue(cOpp)" can return a null value so make sure you check for that before calling the .ToString() method. I don't believe this would cause Act to crash but your plugin will run into issues if the value of the field is blank.

 

You can do something like the following

 

string str1 = "";
object oStr1 = mefd.GetValue(cOpp);

if (oStr1 != null)
str1 = oStr1.ToString();

 

Ahsan Khalid

Chief Technology Officer
Keystroke Quality Computing Inc.
www.keystroke.ca

Copper Super Contributor
Posts: 478
Country: Australia

Re: Opportunity Field Values - USER7

Thanks for your reply

 

In previous version of the code i had Msg lines and one is still there, mefd comes back as "Opportunity Field 7", as for the log i would not know what i am looking at, i will put in the stuff you have recommended and see what happens

 

Thanks again for your reply


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: Opportunity Field Values - USER7

ok updated and it still produces the error and request shutdown of Act

 

                object oStr1 = mefd.GetValue(cOpp);
                if (oStr1 != null) str1 = oStr1.ToString();

                MessageBox.Show("" + str1 + "\n\n" + mefd + "", oApp.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

It certainly this part in getting the value of USER7 as the Message came back with only "mefd" and no "str1"

 

And when i changed this line from

                string str1 = "";

to this

                string str1 = "Investment";

Which is one of the options found in USER7, It worked fine with no error and performed the actions required


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: Opportunity Field Values - USER7

I dont understand this now its working

However it is pulling USER7 from the last loaded opportunity and not the one about to be laoded

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 Elite Contributor
Posts: 82
Country: Canada

Re: Opportunity Field Values - USER7

What event are you using to run the above code? Is it ActApplication.ViewLoaded ?

Ahsan Khalid

Chief Technology Officer
Keystroke Quality Computing Inc.
www.keystroke.ca

Copper Super Contributor
Posts: 478
Country: Australia

Re: Opportunity Field Values - USER7

yes was i have now changed back to CurrentOpportunityChanged, before it created a loop, but i was not thinking clearly and had the solution in hand about to test it now

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: Opportunity Field Values - USER7

Nope still looping ...AAAARRRR


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: Opportunity Field Values - USER7

Ok change it and added a bit of loop breaker etc, its not sexy but appears to work

 

       void oApp_CurrentOpportunityChanged(object sender, EventArgs e)
        {
         
            string viewName = oApp.CurrentViewName;
            // Returns 
            // Act.UI.IOpportunityDetailView
            // Act.UI.IOpportunityListView
            // Act.UI.IOpportunityView
            // Act.UI.ICompanyDetailView
            // Act.UI.ICompanyListView
            // Act.UI.ICompanyView
            // Act.UI.IContactDetailView
            // Act.UI.IContactListView
            // Act.UI.IContactView
            // Act.UI.IGroupDetailView
            // Act.UI.IGroupListView
            // Act.UI.IGroupView

            if (viewName == "Act.UI.IOpportunityDetailView")
            {

                // Function to return the name of current layout
                Act.UI.LayoutDesigner.LayoutFileInfo InfoLayout1;
                InfoLayout1 = oApp.UILayoutDesignerManager.GetCurrentLayout(Act.UI.LayoutDesigner.LayoutType.opportunity);
                
                string cLayout = InfoLayout1.ToString();
                string lstr1 = "";

                if (cLayout == "Basic Opportunity Layout - 1024x768.oly") lstr1 = "Default";
                if (cLayout == "JDFP Opportunity Layout 1.oly") lstr1 = "Investment";
                if (cLayout == "JDFP Opportunity Layout 2.oly") lstr1 = "Superannuation";
                if (cLayout == "JDFP Opportunity Layout 3.oly") lstr1 = "Insurance";

                string str1 = "";

                // Get Current Opportunity
                Opportunity cOpp = oApp.ApplicationState.CurrentOpportunity;

                MutableEntityFieldDescriptor mefd = oApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(StandardOpportunityField.User7);
                object oStr1 = mefd.GetValue(cOpp);
                if (oStr1 != null) str1 = oStr1.ToString();

                MessageBox.Show("" + str1 + "\n\n" + mefd + "", oApp.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (lstr1 != str1)
                {
                    if (str1 == "Investment")
                    {

                        // Creates and obtains list of all current Opportunity layouts available 
                        Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                        InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                        // Returns 
                        // InfoLayout 0 Returns "Basic Opportunity Layout - 1024x768.oly" - Default
                        // InfoLayout 1 Returns "Basic Opportunity Layout - 1366x768.oly"
                        // InfoLayout 2 Returns "Basic Opportunity Layout - 1920x1080.oly"
                        // InfoLayout 3 Returns "Basic Opportunity Layout - 800x600.oly"
                        // InfoLayout 4 Returns "JDFP Opportunity Layout 1.oly" - Investment
                        // InfoLayout 5 Returns "JDFP Opportunity Layout 2.oly" - Superannuation
                        // InfoLayout 6 Returns "JDFP Opportunity Layout 3.oly" - Insurance

                        oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[4]);

                    }
                    else
                    {
                        if (str1 == "Superannuation")
                        {
                            Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                            InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                            oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[5]);
                        }
                        else
                        {
                            if (str1 == "Insurance")
                            {
                                Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                                InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                                oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[6]);
                            }
                            else
                            {
                                Act.UI.LayoutDesigner.LayoutFileInfo[] InfoLayout2;
                                InfoLayout2 = oApp.UILayoutDesignerManager.GetAvailableLayouts(Act.UI.LayoutDesigner.LayoutType.opportunity);
                                oApp.UILayoutDesignerManager.SetCurrentLayout(InfoLayout2[0]);
                            }
                            // End Insurance
                        }
                        // End Superannuation
                    }
                    // End Investment
                }
                else
                {
                    //Nothing
                }
                // End of Opportunity View
            }
        }

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: Opportunity Field Values - USER7

[ Edited ]

Usually when you go into an event handler the first thing you want to do is unsubscribe the event handler you are in from the event.  Then when you exit your event handler you subscribe your event handler back to the event.  That way your event handler doesn't get executed multiple times when an event gets fired multiple times while you are in it.


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!