web
You’re offline. This is a read only version of the page.
close
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

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    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 :)

  • Suggested answer
    Joseph McGregor Macdonald Profile Picture
    597 on at

    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

  • Suggested answer
    Dmytro Rutkovskyi Profile Picture
    1,835 on at

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


  • Tanya12 Profile Picture
    15 on at

    Hi Mohammad,

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans