Identify the Source of Records Created From Microsoft Portal in Dynamics 365

By | September 7, 2018

Introduction:

Microsoft Portals can be accessed by authenticated and as well as anonymous contacts. So if a user has privileges to create records in Dynamics CRM, irrespective of the fact that they are logged into the Portal or not, then when such records get created in CRM-owner of those records will be set as SYSTEM.  But if we want to know who actually created the records from Portal in CRM and from which IP address (for anonymous access), then by doing some portal configurations, we can achieve this goal. For this purpose, we need to have two fields – “Created By(Portal Contact)” and “Created By(IP Address)”. These two fields are already present as OOB fields in Contact and Account entities in CRM where portal is configured. Please note that in CRM where Custom Portal is configured(instead of Partner Portal), the field “Created By (Portal Contact)” is present as “Created By (Portal User)” in Account and Contact entities. But for other entities, we can make the above mentioned fields as custom fields for the same purpose in CRM where Partner Portal/Custom Portal is configured. The field “Created By (IP Address)” should be a single line text field and the field “Created By (Portal Contact)” should be a lookup field of contact type.

So here’s how we can know who created entity records from Portal to CRM and from where. As a demonstration purpose, I am going to use a Contact entity as an example.

Steps To Identify Which Contact In CRM Created Records From Portal To CRM

Here when a user logs into the Portal and creates an entity record, follow the following steps to identify who was that particular contact in CRM who logged into the Portal and created the entity record in CRM from the portal.

1. On the Entity Form Of Contact (or any Entity you would like to configure) used in the Web Page where the logged in person creates contact, check the option of  “Associate Current Portal User” on saving the contact record from Portal as seen and highlighted in the screenshot below. This screenshot is of an Entity form made for Contact Entity which we are considering as an example.

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

2. Now select the field – “Created By(Portal Contact)” among the list of lookup fields which is used to identify that for which field-the logged in contact(of CRM)must be set as a reference in the newly created contact record. Please see the below screenshot for the same especially the highlighted parts.

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

3. Save these two settings(mentioned in the two steps above) on the Entity form.

4. Now whenever a contact gets created from the Portal, the field “Created By (Portal Contact) will have the reference of logged in portal contact member. Please check the below screenshot of the advanced find of contacts created (post the settings we did above).

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

As seen in the screenshot above, even though the Owner of newly created contacts was set as “System”, the value in “Created By (Portal Contact)”-“Vincent Lauriant” indicates it’s the contact “Vincent Lauriant” created the new contacts by logging into the portal. The below screenshot indicates the same too that Vincent is a contact record in CRM with portal access.

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

Steps To Identify From Which IP Address Records Got Created From Portal To CRM

Here is a contact in CRM logins to the portal and creates an entity record OR when a user access Portal without logging to the portal and creates an entity record, follow the following steps to identify from which IP address does this anonymous user created the entity record in CRM from portal.

1. Add the field “Created By (IP Address)” to the form selected in the Entity Form. For example, in the Entity Form taken as an example here, we are using the form “Profile Web Form” of Contact entity. And in that, we have added the field “Created By (IP Address)” in the tab-“General” which is the tab used in the Entity form as seen in the screenshots below. Also please make sure to uncheck the option to display label name of “Created By (IP Address)” field on form as we are later going to keep the field in the background by script(Will tell the reason for it when that step comes).

Entity Form Screenshot

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

Contact Form Screenshot

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

 

Properties of “Created By IP Address” field on the form Screenshot

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

2. Save and publish the changes in the form chosen in the Entity Form, which here is “Profile Web Form” of contact entity.

3. Now on the entity form, we will put our script code in the Entity form which will retrieve IP address when the page gets loaded where the logged in portal contact will create a new contact from the portal. Please see the below screenshot where we put our script in the Entity form in the highlighted section-“Custom Javascript” of Entity Form.

Identify the Source of Records Created From Microsoft Portal in Dynamics 365

4. Below is the code to retrieve Public IP Address which is called when the web page to create contacts gets loaded.

$(document).ready(function (){   
//read the public IP address   
$.getJSON('https://api.ipify.org?format=json', function(data){     
//set the retrieved public IP address to the text field-Created By IP Address 
//whose logical name(in our example) is adx_createdbyipaddress     
$("#adx_createdbyipaddress").val(data.ip);     
//hide the text field-Created By IP Address on the form     
$("#adx_createdbyipaddress").hide(); 
}); 
});

5. Please note that as we are setting the value to the field “Created By IP Address” in the background, the column must be kept visible in the original form(“Profile Web Form”)and after setting the value, we are hiding the field via script as user is NOT expected to enter his IP Address. If we make the field hidden in the original form(“Profile Web Form”), then the script won’t run and no IP Address would be set when the contact gets saved.

6. Here’s the screenshot of contact created from portal with his public IP addresses

Conclusion:

Using the above steps we can find out the source of Dynamics 365 CRM records created from Microsoft Portal.

Cut short 90% of your manual work and repetitive data entry!

Get 1 Click apps and say goodbye to all repetitive data entry in CRM –
Click2Clone – Clone/Copy Dynamics 365 CRM records in 1 Click
Click2Export – Export Dynamics 365 CRM Report/CRM Views/Word/Excel template in 1 Click
Click2Undo – Undo & Restore Dynamics 365 CRM data in 1 Click

6 thoughts on “Identify the Source of Records Created From Microsoft Portal in Dynamics 365

  1. Abirami

    Thank you for the post. I tried this method to get contact details who created the record in portal and I got the result. But when I try the same for modified by this method doesn’t work. Kindly help me here.

    1. Inogic

      You can use the “adx_modifiedbyusername” and “adx_modifiedbyipaddress” field the same way and then write the code on entity form with EDIT mode.

      Note: Add the “Modified By Username, Modified By IP Address” field on the form and hide its label.

      Here is the piece of code you need to write down in the Entity Form -> Additional Settings -> Custom Javascript:

      $(document).ready(function (){
      //Get Current Logged In Username to Portal
      var username = ‘{{ user.adx_identity_username }}’;

      //read the public IP address
      $.getJSON(‘https://api.ipify.org?format=json’, function(data){
      //set the retrieved public IP address to the text field-Created By IP Address

      //whose logical name(in our example) is adx_modifiedbyipaddress
      $(“#adx_modifiedbyipaddress”).val(data.ip);
      //hide the text field-Modified By IP Address on the form
      $(“#adx_modifiedbyipaddress”).hide();

      //current logged in username is adx_modifiedbyusername
      $(“#adx_modifiedbyusername”).val(username);
      //hide the text field-Modified By Username on the form
      $(“#adx_modifiedbyusername”).hide();
      });
      });

      Output Screen clip:

      Hope this helps.

      Thanks!

  2. Emmet Conefery

    Hello, Your post was great.
    But i also have a similar question on this article.
    If i try use [Associate Portal Contact on Insert] using an Edit form, it does not work. Is this not an option?

    1. Inogic

      Hi Emmet,

      We are glad that you liked our post.

      However to answer your query – Yes this approach might not work for the edit form as you may see the name itself suggests that ‘Associate Current Portal User on Insert’.

      Having said that we would like to highlight an alternative approach to achieve the same.

      As we are aware that for an Entity Form we can very much create an Entity Form Metadata. So to achieve this as well, we will need to create an Entity Form Metadata for your edit Entity Form.

      This Metadata will be created with the Type as Attribute and in the field Attribute Logical Name select the respective Contact lookup (from the list of lookup fields present for that entity) where you want to map the logged in portal contact. Then you need to scroll down to the section Set Value On Save. Here you need to set the values as per the screenshot below and save the record.

      Because of the Metadata created above every time you submit the edit form it will capture the logged in portal user and store it in the specified contact lookup.

      Hope this helps.

      Thanks!

  3. Bikram

    Hi, I have a similar requirement , I have a entitylist, that runs a workflow which just changes the status of a record, but modified by is set to System. I have created a new attribute and am able to update it on an entity form when a user changes the status. But on the entity list it is failing. any idea how I can get this to work..

    Thanks

    1. Inogic

      As of now there is no OOB way on Entity List to pre-populate the Modified By lookup field with current logged in user of PowerApps portal. This functionality is available only at entity form in which you were also able to successfully achieve as per the blog.

      Thanks!

Comments are closed.