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

Dynamics 365 Function Parameters (need to remove quote) #931

Open
Slackter opened this issue Mar 29, 2024 · 1 comment
Open

Dynamics 365 Function Parameters (need to remove quote) #931

Slackter opened this issue Mar 29, 2024 · 1 comment

Comments

@Slackter
Copy link

Slackter commented Mar 29, 2024

Hello,

We are utilizing the latest version of this library very heavily without any issues at all so it's been great. We are in need of executing a function and need to specify a function parameter in a very specific format.

The function requires a parameter of Target=@tgt (@tgt can be anything) but there must be NO quotes at all.

If I run use the following code:
client.For<SystemUser>.Key(userGuid).Function("RetrievePrincipalAccess").Set(new { Target = "@tgt })

the library will generate a URL as follows:
https://server/api/data/systemusers(userGuid)/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target='@tgt')

when it needs to be:
https://server/api/data/systemusers(userGuid)/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@tgt)

Is there any way to remove the single quotes the Set() is adding to my URL?

I was able to get this working by using the BuildRequestFor() and modifying the RequestUri directly, but I am unable to write proper unit tests since the ODataRequest has only internal constructors and is un-mockable.

@ExpDev07
Copy link

I ran into the same issue, the following solved it for me (though it would be nice of they supported a SerializationOption for the key to control this behavior):

public class AbstractApi(HttpClient httpClient, Uri relativeUri) : ODataClient(new ODataClientSettings(httpClient, relativeUri)
{
    IgnoreUnmappedProperties = true,
    BeforeRequest = m => m.RequestUri = m.RequestUri.RemoveUnsupportedQuotes()
});

public static class AbstractApiExtensions
{
    public static Uri? RemoveUnsupportedQuotes(this Uri? uri)
    {
        if (uri == null)
        {
            return uri;
        }
        
        var newUri = uri.ToString();
        newUri = newUri.Replace("(%27", "(");
        newUri = newUri.Replace("%27)", ")");

        return new Uri(newUri);
    }
}

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