Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

unable to retrieve user id while calling the javascript using webfiles in crm portal

(0) ShareShare
ReportReport
Posted on by 25

hi,

we wrote a java script to retrieve the current user details(i.e. who ever makes changes in crm portal) and it is working when the script is placed in  custom java script in entity form but when we tried to call from tracking code using webfiles the user id is not getting retrieved. could you please help??

*This post is locked for comments

  • Suggested answer
    RE: unable to retrieve user id while calling the javascript using webfiles in crm portal

    Hello Jaithun

    by using liquid code add User ID to a hidden field and use hidden field value in your script (because liquid variables data you cant consume directly in scripts).

    Thanks

    James

  • Suggested answer
    Nicholas Hayduk Profile Picture
    Nicholas Hayduk 2,863 on at
    RE: unable to retrieve user id while calling the javascript using webfiles in crm portal

    Hello,

    You are using Liquid to retrieve the current user.  Liquid is a server-side language that has to be processed by the server before being sent to the browser.  Only certain fields support Liquid - web page copy and summary, custom javascript, etc, but unfortunately web files do not.  So any Liquid contained in a web file will not be evaluated.

    Nick

  • jaithun Profile Picture
    jaithun 25 on at
    RE: unable to retrieve user id while calling the javascript using webfiles in crm portal

    Hi Oliver,

    Yes, we are trying to access the webfile using content snippet (i.e. using tracking code). This script is used in many entity forms , so to reduce the redundancy we tried to call the javascript using webfile.

    Please find below script for more information.

    $(document).ready(function () {

       var clonedSubBtn = "<input type='button' id='InsertButton_Cloned' value='Save' class='btn btn-primary button submit-btn'>";

       var userId = '{{user.id}}';

       $("#UpdateButton").parent().append(clonedSubBtn);

       $("#UpdateButton").hide();

       $("#prc_lastmodifiedbyurl").hide();

       $("#prc_lastmodifiedbyurl_label").hide();

       $('#prc_lastmodifiedbyurl').parents('div[class^="input-group"]').children('div[class^="input-group-btn"]').hide();

       $('#prc_lastmodifiedbyurl_label').parents('div[class^="info"]').hide();

       $('#InsertButton_Cloned').on('click', function (event) {

           var userId = '{{user.id}}';

           var username = '{{user.fullname}}';

           if (userId != null && username != null) {

               var CRMURL = (window.location.href).split(".");

               var URL = CRMURL[0] + ".crm.dynamics.com/main.aspx?etc=2&id=" + userId + "&newWindow=true&pagetype=entityrecord";

               $("#prc_lastmodifiedbyurl").attr("value", URL);

               $("#UpdateButton").trigger('click');

               return false;

           }

           else {

               return false;

           }

       });

    });

  • Suggested answer
    oliver.rodrigues Profile Picture
    oliver.rodrigues 4,052 on at
    RE: unable to retrieve user id while calling the javascript using webfiles in crm portal

    can you give more details on what you trying to achieve ?

    "when we tried to call from tracking code using webfiles".. I didn't understand this part.. tracking code is actually a content snippet.. is the user id being retrieve from that JS ?

    can you share your code ?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans