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)

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

I have the same question (0)
  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at

    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 ?

  • jaithun Profile Picture
    25 on at

    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
    Nicholas Hayduk Profile Picture
    2,863 on at

    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

  • Suggested answer
    Emmaneul James Abraham Profile Picture
    727 on at

    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

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