Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

How does one use a variable in a webapi filter?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Error message: Syntax error at position 22 in 'msdyn_name eq CA-90028'.

Script: 

        if (formContext.getAttribute("shipto_postalcode").getValue() && formContext.getAttribute("shipto_stateorprovince").getValue()) {
            var taxGroupName = formContext.getAttribute("shipto_stateorprovince").getValue()   "-"   formContext.getAttribute("shipto_postalcode").getValue();
            alert(taxGroupName);

            Xrm.WebApi.retrieveMultipleRecords("msdyn_taxgroup", "?$select=msdyn_name&$filter=msdyn_name eq "   taxGroupName).then(

or am I making some simpler syntax error?

TIA

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How does one use a variable in a webapi filter?

    I think there is a way by modifying the ribbon to move the mscrm function from the button to the javascript and replace the command on the button but, I'm hoping there is a more easily maintainable solution.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How does one use a variable in a webapi filter?

    I have placed shipto_name/_stateorprovince/_postalcode fields to the address form and added this method to their onChange events.  Of course, add/change addresses run through an mscrm method attached to the lookup address button/dialog.

    I change the address and can see fields change but the method does not fire until I save; and I have no place to script ".fireOnChange()".

    Hence it saves and comes back dirty.

    ps- for all the kids out there: 

    Xrm.WebApi.retrieveMultipleRecords("msdyn_taxgroup", "?$select=msdyn_name&$filter=msdyn_name eq '"   taxGroupName   "'").then(
    

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How does one use a variable in a webapi filter?

    So what is needed to happen and why a double save?  Maybe I can help get it down to 1.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How does one use a variable in a webapi filter?

    Now, unfortunately I have to figure out a way to have it fire before the order save (double saving required.)

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How does one use a variable in a webapi filter?

    Try single quotes around the taxGroupName

    Go to:

    -assuming your version is 9.1, change as needed.

    YOURCRMBASEURL.com/.../msdyn_taxgroups eq 'CA-90028'

    What comes back?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans