web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to Pass string in Like Operation.

(0) ShareShare
ReportReport
Posted on by 233

Hello ,

I used the below code in ms crm javascript ,it is giving an error if i put the "Like" operator condition so please suggest me how to pass string in a like operator condition. 

var filproduct = Xrm.Page.getAttribute("new_typeoffilproduct").getText();

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='new_customersaleszone'>"+
"<attribute name='new_subdepartment' />"+
"<attribute name='new_saleszone' />"+
"<attribute name='new_department' />"+
"<attribute name='ownerid' />"+
"<attribute name='new_customer' />"+
"<attribute name='createdon' />"+
"<attribute name='new_customersaleszoneid' />"+
"<order attribute='new_subdepartment' descending='false' />"+
"<filter type='and'>"+
"<condition attribute='new_customer' operator='eq' uiname='Customer Sync check from UAT' uitype='account' value='"+customerId+"' />"+
"<condition attribute='new_departmentname' operator='like' value='""%"+filproduct+"%""' />"+
"</filter>"+
"</entity>"+
"</fetch>";

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Looks like you have a format issue on your string concatenation. It should be

    value='%"+filproduct+"%' />"+

    Also you will need to make sure you xml escape the filproduct string so that quote etc are escaped.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Amrutha,

    Agreed with Scott , In addition put a null check before execute fetchXML.

    var filproduct = Xrm.Page.getAttribute("new_typeoffilproduct").getText();
    if (filproduct != null && customerId !=null) {
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "<entity name='new_customersaleszone'>" +
            "<attribute name='new_subdepartment' />" +
            "<attribute name='new_saleszone' />" +
            "<attribute name='new_department' />" +
            "<attribute name='ownerid' />" +
            "<attribute name='new_customer' />" +
            "<attribute name='createdon' />" +
            "<attribute name='new_customersaleszoneid' />" +
        "<order attribute='new_subdepartment' descending='false' />" +
        "<filter type='and'>" +
            "<condition attribute='new_customer' operator='eq' uiname='Customer Sync check from UAT' uitype='account' value='" + customerId + "'/>" +
            "<condition attribute='new_departmentname' operator='like' value='%" + filproduct + "%' />" +
        "</filter>" +
        "</entity>" +
        "</fetch>";

    }


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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans