Find Party by Major Key with SOA

I'm trying to use SOA to find a Party by Major Key.  If a record exists with a specified Major Key then update the Party information, otherwise an insert needs to happen.

An example or sample code of how to find a party by Major Key would be helpful.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Sample code, and caveats

This should get you going (minus checks for null gQuery and pQuery results):

            EntityManager em = new EntityManager("<user>""<password>");
 
            // Query the Name table directly to get the Party associated with majorKey
            QueryData gQuery = new QueryData("Name");
            CriteriaData criteriaValue = new CriteriaData("MAJOR_KEY", OperationData.Equal, "<key_value>");
            gQuery.AddCriteria(criteriaValue);
            var nameRow = em.Find(gQuery).Result[0] as GenericEntityData;
            var partyId = nameRow["PartyId"].ToString();

 
            // Now use the partyId just obtained to get the PartyData record
            QueryData pQuery = new QueryData("Party");
            var result = em.FindByIdentity(new IdentityData("Party", partyId)) as PartyData;            

There is one bug that ASI is working on, in that if you obtain a PartyData record that has a MajorKey, update some other property in that item, and Update it, you will encounter an error on any subsequent retrieval of that item.