Community
Showing results for 
Search instead for 
Do you mean 
Reply

Add an event on a picklist

Accepted Solution Solved
Copper Contributor
Posts: 6
Country: Hong_Kong
Accepted Solution

Add an event on a picklist

Hello, 

Im trying to add an event on a picklist but that doesn't work, I've tried a lot of things but this keep failing if someone has an idea ?

Hope this time, one guy will give 2min of his time to answer. That could be nice.

Thanks, koceila.


Accepted Solutions
Solution
Accepted by topic author koceila
‎05-09-2016 07:10 AM
Copper Contributor
Posts: 6
Country: Hong_Kong

Re: Add an event on a picklist

Hello,

Thanks for your answer, I've already solved the problem. For next guys :

if (fieldName == registration.Name)
{
  os.ListRegistrationUpdate();
}

public void ListRegistrationUpdate()
{
 var o = application.ApplicationState.CurrentOpportunity;
            string choix = Convert.ToString(o.OpportunityFields["Opportunity.License_Registration"]);
            string requete = ReadingRequest.Request(choix, 102);
            if (!(requete.Equals("null")) && !(requete.Equals("Error_Connection_Failed")))
            {
                dynamic registrationSelect = Newtonsoft.Json.JsonConvert.DeserializeObject(requete);
                // La date 0000-00-00 n est pas supporte par le convert on doit donc obligatoirement verifier
                if (!((Convert.ToString(registrationSelect.Registration_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Registration_Date", false] = Convert.ToDateTime(registrationSelect.Registration_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Registration_Date", false] = null;
                }
                if (!((Convert.ToString(registrationSelect.Last_Update_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Last_Update_Date", false] = Convert.ToDateTime(registrationSelect.Last_Update_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Last_Update_Date", false] = null;
                }
                if (!((Convert.ToString(registrationSelect.Last_Use_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Last_Use_Date", false] = Convert.ToDateTime(registrationSelect.Last_Use_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Last_Use_Date", false] = null;
                }
            }
            else
            {
                if ((requete.Equals("Error_Connection_Failed")))
                {
                    MessageBox.Show("Un probleme de connexion est survenu");
                }
                SuppressionRegistrationWithoutListValues();
            }
            o.Update();
        }

Forgot to clean my picklist was one of my mistake too.

 

                    var ACTFM = application.ActFramework;
                    var pickListRegistrationOpportunity = ACTFM.PickLists.GetPickList("License_Registrations_List_Opportunity");
                    while (pickListRegistrationOpportunity.Items.Count > 0)
                    {
                        pickListRegistrationOpportunity.Items.RemoveAt(0);
                    }

View solution in original post


All Replies
Bronze Super Contributor
Posts: 1,284
Country: USA

Re: Add an event on a picklist

Not sure what event you are trying to hook into. SelectedIndexChanged, TextChange, ect

 

Can you pots your code so far?

 

-- Jim 

Solution
Accepted by topic author koceila
‎05-09-2016 07:10 AM
Copper Contributor
Posts: 6
Country: Hong_Kong

Re: Add an event on a picklist

Hello,

Thanks for your answer, I've already solved the problem. For next guys :

if (fieldName == registration.Name)
{
  os.ListRegistrationUpdate();
}

public void ListRegistrationUpdate()
{
 var o = application.ApplicationState.CurrentOpportunity;
            string choix = Convert.ToString(o.OpportunityFields["Opportunity.License_Registration"]);
            string requete = ReadingRequest.Request(choix, 102);
            if (!(requete.Equals("null")) && !(requete.Equals("Error_Connection_Failed")))
            {
                dynamic registrationSelect = Newtonsoft.Json.JsonConvert.DeserializeObject(requete);
                // La date 0000-00-00 n est pas supporte par le convert on doit donc obligatoirement verifier
                if (!((Convert.ToString(registrationSelect.Registration_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Registration_Date", false] = Convert.ToDateTime(registrationSelect.Registration_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Registration_Date", false] = null;
                }
                if (!((Convert.ToString(registrationSelect.Last_Update_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Last_Update_Date", false] = Convert.ToDateTime(registrationSelect.Last_Update_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Last_Update_Date", false] = null;
                }
                if (!((Convert.ToString(registrationSelect.Last_Use_Date)).Equals("0000-00-00")))
                {
                    o.OpportunityFields["Opportunity.License_Last_Use_Date", false] = Convert.ToDateTime(registrationSelect.Last_Use_Date);
                }
                else
                {
                    o.OpportunityFields["Opportunity.License_Last_Use_Date", false] = null;
                }
            }
            else
            {
                if ((requete.Equals("Error_Connection_Failed")))
                {
                    MessageBox.Show("Un probleme de connexion est survenu");
                }
                SuppressionRegistrationWithoutListValues();
            }
            o.Update();
        }

Forgot to clean my picklist was one of my mistake too.

 

                    var ACTFM = application.ActFramework;
                    var pickListRegistrationOpportunity = ACTFM.PickLists.GetPickList("License_Registrations_List_Opportunity");
                    while (pickListRegistrationOpportunity.Items.Count > 0)
                    {
                        pickListRegistrationOpportunity.Items.RemoveAt(0);
                    }
Tuned Listener
Posts: 11
Country: Guatemala

Re: Add an event on a picklist

Hey Jim.

 

Do you have sample code to hook into selectedindexchanged or textchange, looking the runtime object tree the objects are instances of  act.ui.picklist.nupicklist,

 

Already tried to attach event handlers for textchange and lost focus, but basically the delegate never gets called.

 

        void application_ViewLoaded(object sender, ViewEventArgs e)
        {

            if (this.application.CurrentViewName == "Act.UI.IContactDetailView")
            {
                   panels = this.application.Controls[0].Controls["ContactDetailView"].Controls["PanelTabs"].Controls[0].Controls["Purchased"];

                    foreach (Control cl in panels.Controls)
                    {
                                if(cl.GetType().FullName.Contains("Act.UI.PickList"))
                                {
                                         MethodInfo method = typeof(Plugin).GetMethod
                                                                ("HandleEvent", BindingFlags.Public | BindingFlags.Instance);
EventInfo eventInfotc = cl.GetType().GetEvent("TextChanged");
                                        Type typetc = eventInfotc.EventHandlerType;
                                        Delegate handlertc = Delegate.CreateDelegate(typetc, this, method);

                                        eventInfotc.AddEventHandler(cl, handlertc);
                                }
                     }
            }

        }