Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with ExecuteAction #38

Closed
ChrisKoenig opened this issue May 11, 2017 · 5 comments
Closed

Error with ExecuteAction #38

ChrisKoenig opened this issue May 11, 2017 · 5 comments

Comments

@ChrisKoenig
Copy link

I'm getting an error when I execute the action associated with running a full-text search on the KnowledgeArticle entities:

function getArticles(phrase, fn) {
    var action = "FullTextSearchKnowledgeArticle";
    var params = {
        'SearchText': phrase,
        'StateCode': 1,
        'QueryExpression': {
            'ColumnSet': ['title', 'description', 'articlepublicnumber'],
            'EntityName' : 'knowledgearticle'
        }
    };
    crmApi.ExecuteAction(action, params).then(function(r) {
        fn(r);
    }, function(e) {
        logError('getArticles', e);
    });
}

The error returned is:

The property 'ColumnSet' does not exist on type 'Microsoft.Dynamics.CRM.QueryBase'. Make sure to only use property names that are defined by the type.

What I need to be able to do is specify the QueryExpression parameter as a type Microsoft.CRM.Dynamics.QueryExpression instead of it's base class, Microsoft.Dynamics.CRM.QueryBase.

Any ideas on how to do this? Hopefully I'm just missing something that should be obvious...

@davidyack
Copy link
Owner

Hey Chris - have you tried this in a generic tool like Postman to see if it works? I've not used this particular action but will check around to see if anyone has successfully used it

@ChrisKoenig
Copy link
Author

No, I've not tried that, but I will look into it. I'm suspecting that this particular function is going to be tricky as it takes one of several types for QueryExpression per the documentation, all subclasses of QueryBase and I don't know if JavaScript can "understand" subclasses in the same way that languages like C# can. Do you know how to do this?

@davidyack
Copy link
Owner

I would try adding '@odata.type':'mscrm.QueryExpression' to the QueryExpression object - I sent a query off to see if Microsoft has an example of the JSon for this particular action

@ChrisKoenig
Copy link
Author

ChrisKoenig commented May 17, 2017 via email

@ChrisKoenig
Copy link
Author

I was finally able to get this working. There is at least one bug with the Javascript-compatible syntax for the API itself, but the action is now working. Here's my sample code to help close this loop (note: my sample is part of a BotFramework project, and this is coming from my CRM helper class):

exports.getArticles = function (session, keyword) {
    return new Promise((resolve, reject) => {
        _authenticate(crmServerUrl, crmUsername, crmPassword, adalHostUrl, adalClientId)
            .then((api) => {
                var fieldArray = ["title", "isinternal", "description", "articlepublicnumber", "modifiedon", "statecode", "keywords"];
                var action = "FullTextSearchKnowledgeArticle";
                var parms = {
                        'SearchText': keyword,
                        'UseInflection': false,
                        'RemoveDuplicates': true,
                        'StateCode': 3,
                        'QueryExpression': {
                            '@odata.type': "Microsoft.Dynamics.CRM.QueryExpression",
                            'EntityName': 'knowledgearticle',
                            'ColumnSet': {
                                '@odata.type': "Microsoft.Dynamics.CRM.ColumnSet",
                                'Columns': fieldArray,
                            },
                            "PageInfo": {
                                "Count": 10,
                                "ReturnTotalRecordCount": true
                            },
                            "Orders": [{
                                "AttributeName": "modifiedon",
                                "OrderType": "Descending"
                            }]
                        }
                    };

                api.ExecuteAction(action, parms).then(
                    function (output) {
                        resolve(output.value);
                    },
                    function (error) {
                        reject(error);
                    });
            });
    });
}

What was missing from before was the PageInfo entity. Once I supplied that, I started getting results back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants