last day (16 days later) » 

14:10
1
Q: Find all contacts having a specified parent account in query expression

JK.I'm using this query to find all contacts with a specified accountid as the parentcustomerid field of the contact entity. The accountId variable is of type Guid. QueryExpression query = new QueryExpression() { EntityName = "contact", ColumnSet = new ColumnSet(true), Criteria = { ...

JK.
JK.
It means that the plugin is registered as a "pre-operation" (which implies that the code is executed before the actual deletion of the entity).
your query is fine and I just tested it, ergo there are no contacts matching your accountId value as parent customer
JK.
JK.
@Guido Preite True. But I see active contacts in CRM having the account as "Linked To Customer" but they don't show up in query results. Suggestions?
"linked to customer" what means? by connection? did you try to run an advanced find inside CRM with the specific account as parent customer?
JK.
JK.
Yes, that query returned results.
@Guido Preite "Linked to customer" is a field on the contact form where an account can be set as parentcustomerid.
14:10
"Linked to customer" is the label of this field? are you sure is still parentcustomerid or is a custom field? sorry if looks like I ask dumb questions but just to exclude misunderstandings
JK.
JK.
The "weird" thing is that the exact same thing works in an advanced query
without see your crm, my best guess is that field is not parentcustomerid
JK.
JK.
hmm, but in the advanced query I use "Parent Customer Equals _thesamecompanyasguid"
So, it MUST be that! =)
very strange, as I said i run a test in my environment, set an account as parent customer and run your query and got the result.
You can do a test
get the contact id
and run a service.Retrieve with columnset(true)
inside the debugger of visual studio
check the attributes of the Entity object
JK.
JK.
Did that, no result for this account
Works with other accounts
14:15
so a service.retrieve with the account guid also give no results?
and you are able to see this account inside CRM?
JK.
JK.
A service retreive with a hardcoded accountid as parentcustomerid does not work for this accont
your application runs with the same credentials as you use web crm?
JK.
JK.
I clearly see it in CRM and I see the contacts in CRM and the andvance query for this exact comapny works in crm
It runs a plugin
*It runs as a plugin
and I can manage to get results for other account
but did you try this ? Entity account = service.Retrieve("account", accountId, new ColumnSet(true));
JK.
JK.
I try that, get back to you...
14:17
ok
JK.
JK.
Yes, I can find that account
ok, so get the id of this contact
and do a Entity contact = service.Retrieve("contact", contactId, new ColumnSet(true));
and after because you are inside a plugin
do a
a moment
after write: EntityReference parent = (EntityReference)contact["parentcustomerid"];
and after: throw new InvalidPluginExecutionException(parent.Id.ToString());
if the plugin is synchronous you will get the alert and check the result id
of course if you are debugging the plugin you can get the value from visual studio
JK.
JK.
Business Process Error
14:33
means that contact has no parentcustomerid
JK.
JK.
OK, do you know why it can be found in advanced query then?
a moment
JK.
JK.
If we can't get this to an "answer" I'll just upvote 3 of your best answers on other questions
I really appriciate your time
        if (contact.Contains("parentcustomerid"))
        {
            if (contact["parentcustomerid"] != null)
            {
                var check = contact["parentcustomerid"];
                throw new InvalidPluginExecutionException(check.ToString());
            }
            else
            {
                throw new InvalidPluginExecutionException("is null");
            }
        }
        else
        {
            throw new InvalidPluginExecutionException("parentcustomerid not set");
in this way we can get the situation, if the code arrive to check.ToString we can know what there is inside
JK.
JK.
Hmm, Business Process Error again
I'm not sure the CRM API takes to kindly to that contact
14:43
can you post here your plugin or at least the relevant part of code?
JK.
JK.
try{
Entity contact = Service.Retrieve("contact", new Guid("3177741D-27BA-DE11-AC0C-0018717A8C82"), new ColumnSet(true));
if (contact.Contains("parentcustomerid"))
{
if (contact["parentcustomerid"] != null)
{
var check = contact["parentcustomerid"];
throw new InvalidPluginExecutionException(check.ToString());
}
else
{
throw new InvalidPluginExecutionException("is null");
}
}
else
{
throw new InvalidPluginExecutionException("parentcustomerid not set");
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException(
"An error occurred in the " + this.GetType().Name + " plug-in.", ex);
}
can you remove for now the try/catch statement?
JK.
JK.
Why? I can still see the error in the log I guess?
in this way we are use that the original invalidpluginexception message is displayed
JK.
JK.
yes but now it wasn't thrown
If it had been thrown we had seen it
14:47
strange, because my code will sure throw an exception
JK.
JK.
sry, you meant the last one
=)
the plugin is synchronous
yes, i meant remove the try statement and the relative catch, mantaining my code
JK.
JK.
But your code is maintained
I'm not catching your exceptions
strange
if you want we can do a teamviewer session (meeting type, means i can only watch your monitor)
JK.
JK.
Not sure if I'm confortable with that, and I'm not going to bother you anymore with this.
Service.Retrieve("contact", new Guid("3177741D-27BA-DE11-AC0C-0018717A8C82"), new ColumnSet(true));
seems like that cannot be done and throws Business Model Error. I'll read up more on that.
14:53
if is this line throws the error means the guid is wrong
but inside there you need to put the guid of the contact
JK.
JK.
that is the guid of the contact
you know how many upvotes I can give before it will bounce back?
I think no, because in that case you will get an error also when you open the record
the plugin run in your context?
JK.
JK.
hmm, true
or the step is configured to run in someone else context?
I think this is the last possible check in my mind now to figure out the problem
JK.
JK.
Yes, thank you very much!
A good way to say thanks? Since marking answer as accepted doesn't really work this time.
14:57
don't worry abou that
Now i need to go, hope you figure out to make it working
JK.
JK.
OK, thanks for your time. Have a good evening.

  last day (16 days later) »