Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

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

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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:
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can i consume web template service in ms crm portal using entity form.

    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%}

    }

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How can i consume web template service in ms crm portal using entity form.

    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
    Community Member Microsoft Employee on at
    RE: How can i consume web template service in ms crm portal using entity form.

    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
    Mahendar Pal 45,095 on at
    RE: How can i consume web template service in ms crm portal using entity form.

    Recheck your code for error, like below

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

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans