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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer Service forum

How can i consume web template service in ms crm portal using entity form.

(0) ShareShare
ReportReport
Posted on by

i have fetchxml in web template and i want to get data on a particular record through entity form.

So, i want to consume this web template.

I wrote the code but my ajax does not work properly, i'm triggering it on change event.

Its only ajax which does not work. Let me know if there is mistake or how can i debug it.

My Code

$(document).ready(function () {
$("#ics_product").change(function () {
var prodname=$(ics_product_name).val();
var orderid = getQueryStringByName('id');
var url = '/getproductprice/?product='+prodname;

$.ajax({
type: "GET",
url: url,
dataType: 'json',
async: false,
success: function (result) {
var order = result;
order.forEach(function (element) {

alert("Hi");

});
}
}).done(function (json) {

}).always(function () {
$("#loading").fadeOut();
});

});
});
function getQueryStringByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}








Categories:
I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Recheck your code for error, like below

    var prodname=$('#ics_product_name').val();

  • Community Member Profile Picture
    on at

    Hi Mahendra,

    I'm able to pick the value. SO i thinkk its fine. But when i select my product from look up. i does not get selected. that is the only issue i have with this code. But if i take off ajax part then i can select the product from look up.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    If you have setup web template correctly and entity permissions below code should give you result, not tested but this should work 

    <script>

    $(document).ready(function() {
    $("#ics_product").change(function () {
    var prodname=$('#ics_product_name').val();
    getProductDetailsByName(prodname);
    });
    function getProductDetailsByName(prodname) {
    var url = '/getproductprice/?product=' + prodname;
    $.ajax({
    type: "GET",
    url: url,
    dataType: 'json',
    async: false,
    }).done(function (json) {
    if (json.length > 0)
    var result = json[0];
    if (result != null || result != 'undefined') {
    var price=result.ics_price; //change field name here
    alert(price);
    });
    }
    });

    });
    </script>

  • Community Member Profile Picture
    on at

    Hi Maender,

    All is fine now, i can select product. but i think i'm not able to consume the web template because my alert does not come up.

    my code

    $(document).ready(function () {

    $("#ics_product").change(function () {

    var prodname=$(ics_product_name).val();

    var orderid = getQueryStringByName('id');

    var url = '/getproductprice/?product='+prodname;

    $.ajax({

    type: "GET",

    url: url,

    dataType: 'json',

    async: false,

    }).done(function (json) {

       if(json>0){

           var test=json.unit;  

           alert(test);

       }

    });

    });

    });

           function getQueryStringByName(name, url) {

        if (!url) url = window.location.href;

        name = name.replace(/[\[\]]/g, "\\$&");

        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),

            results = regex.exec(url);

        if (!results) return null;

        if (!results[2]) return '';

        return decodeURIComponent(results[2].replace(/\+/g, " "));

    }

    // my web temp

    {%fetchxml query%}

    <fetch version="1.0" output-format="xml-platform" returntotalrecordcount="true" mapping="logical" distinct="false">

     <entity name="ics_productmaster">

       <attribute name="ics_productmasterid" />

       <attribute name="ics_productcode" />

       <attribute name="ics_mrp" />

       <attribute name="createdon" />

       <order attribute="ics_productcode" descending="false" />

       <filter type="and">

         <condition attribute="ics_productcode" operator="eq" value="{{request.params['product']}}" />

       </filter>

     </entity>

    </fetch>

    {%endfetchxml%}

    {

    {% for result in query.results.entities %}

       "value":[{

           "count": "{{ query.results.total_record_count }}" ,

           "unit": "{{result.ics_mrp}}"

       }]

    {% unless forloop.last%},{%endunless%}

    {%endfor%}

    }

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans