Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to call CRM web API using portal web form with best practice

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all, 

I have a requirement to create a custom page in Dynamics CRM portal with one text box so the customer can fill it with a case number and a button to retrieve the case status. What is the best practice to achieve this requirement without exposing any credentials on the client side? 


*This post is locked for comments

  • Tanya12 Profile Picture
    Tanya12 15 on at
    RE: How to call CRM web API using portal web form with best practice

    Hi Mohammad,

    Can u please elaborate the integration of web application with d365 portal

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    Dmytro Rutkovskyi 1,835 on at
    RE: How to call CRM web API using portal web form with best practice

    You can use what Joseph has proposed with oData and Entity List. But in case you want to output some specific information about case and especially if you need output something from connected entities - it can be quite complicated and require more ajax requests to different odata endpoints.

    You can use liquid instead.

    Again, create entity permission for cases (use scope as global - for test period), and allow this permission for authenticated users role.

    Create page -> which derive from custom page template -> which derive from custom web template:

    mentioned code output textbox to input text, and allow you to search this text in all cases numbers (you can easily change this condition). As well I have added condition to look in only active cases. This approach didn't do any external/internal ajaxcalls and can be extended for even better security based on current user roles/relationships/data. 

    {% extends "Layout 1 Column" %}
    
    {% block main %}
    
    <form method="post">
    <input type="textbox" name="caseid" id="caseid" />
    <input type="submit" value="Search" id="btnsearch" ></button>
    {% if request.params["caseid"] %}
       {%assign caseid = request.params["caseid"] %}
       
      
     {% fetchxml cases %}
       <fetch top="20" no-lock="true" >
         <entity name="incident" >
          <attribute name="title" />
          <attribute name="ticketnumber" />
          <filter>
           <condition attribute="statecode" operator="eq" value="0" />
           <condition attribute="ticketnumber" operator="like" value="%{{caseid|h}}%" />
          </filter>
         </entity>
       </fetch>
       {% endfetchxml %}
    
       {%if cases.results.entities.size > 0 %}
    
          <div> Result ({{cases.results.entities.size}}) for search ({{caseid|h}}): </div>
       
         {%for e in cases.results.entities %}
            {{e.title}} ({{e.ticketnumber}}) <br/>
         {%endfor%}
    
        {%else%}
        <i>there are no results</i>
       {%endif%}
    {%endif%}
    </form>
    
    {%endblock%}


  • Suggested answer
    RE: How to call CRM web API using portal web form with best practice

    Hi Mohanned

    Assuming you are using Microsoft Portal using the WebAPI is probably not appropriate. I think you should be able to do this by creating an Entity List configured as an ODatafeed without Entity permissions turned on. Just make sure you do not include any information in the view which is sensitive

    So basically you would

    1. Create an Entity List record configured for a Case view which contains only the status. Ensure "Enable Entity Permissions" is set to false, and set the fields in the OData Feed section

    2. Create a web page with a text box and button. When the button is clicked do an Ajax call to the OData feed with a filter for the case number. This should return the status of the case

    Hope this helps

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to call CRM web API using portal web form with best practice

    Hi Mohannad,

    Supposing you are adding a new ASP.net web page to the portal solution, in its code behind, implement the On_Click event of the button. 

    You need to make sure that your page code behind class implements the "PortalPage" interface already defined by Microsoft in the Portal source, then use the service as below:

    4276.service.PNG

    This is mainly how to use the portal service. Now you have the service, you can get the case status by Case Number, then get the label of this status using the below method:

    public string GetSystemOptionSetText(string entityName, string attributeName, int optionSetValue)
    {
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
    {
    EntityLogicalName = entityName,
    LogicalName = attributeName,
    RetrieveAsIfPublished = true
    };

    RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)_CRMService.Execute(attributeRequest);
    AttributeMetadata attrMetadata = attributeResponse.AttributeMetadata;

    StatusAttributeMetadata statusAttrMetadata = (StatusAttributeMetadata)attrMetadata;

    string statusCodeLabel = "";

    foreach (StatusOptionMetadata statusMeta in statusAttrMetadata.OptionSet.Options)
    {
    if (statusMeta.Value == optionSetValue)
    {
    statusCodeLabel = statusMeta.Label.UserLocalizedLabel.Label;
    }
    }

    return statusCodeLabel;
    }

    Regards,

    Hope it helps! If it does, please mark this answer as Verified, this will be greatly appreciated :)

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans