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)

Javascript show icon in view

(0) ShareShare
ReportReport
Posted on by 600

Hi 

I am trying to show a icon in a subgrid/view with the following javascript, but it is not working?

function checkTest(rowData, userLCID) {
var str = JSON.parse(rowData);
var coldata = str.scheduledend_Value;
var imgName = "";
var tooltip = "";

if (coldata) {
var subjectText = Xrm.Page.getAttribute("subject").getValue();
var testdrive = subjectText.includes("testdrive");
var prøvekjøring = subjectText.includes("prøvekjøring");
if (prøvekjøring == true || testdrive == true) {
imgName = "mb_datePassed";
tooltip = "Forventet dato for signering er passert";
}

}
var resultarray = [imgName, tooltip];
return resultarray;
}

Any ideas what is wrong?

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Martin,

    You can not get value of a field using Xrm method in the view . If you want to get the value , you need to be included in the view itself and try to get the value from coldata and then use case statement .

    For example :

     var str = JSON.parse(rowData);

       var sub = str.subject

    Try to hide the condition code , hope you will see the icon without condition . Try with below code. Make sure you are providing correct image url. For more information please have a look below reference -

    http://mscrmshop.blogspot.com/2016/12/adding-icons-and-tooltips-to-grid.html

      function checkTest(rowData, userLCID) {
          var str = JSON.parse(rowData);
          var coldata = str.scheduledend_Value;
          var imgName = "";
          var tooltip = "";
    
          if (coldata) {
              //var subjectText = Xrm.Page.getAttribute("subject").getValue();
              //var testdrive = subjectText.includes("testdrive");
              //var prøvekjøring = subjectText.includes("prøvekjøring");
              //if (prøvekjøring == true || testdrive == true) {
                  imgName = "mb_datePassed";
                  tooltip = "Forventet dato for signering er passert";
             // }
    
          }
          var resultarray = [imgName, tooltip];
          return resultarray;
      }


    Hope this helps .

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    It looks like coldata is of type date and you are checking it as bool i.e. if (coldata). Put some alert or debug it to check the value returned and change your code accordingly.

    If still doesn't work, share some more details about your entity, fields and data type.

    Hope this helps.

  • martingr Profile Picture
    600 on at

    Thank you.

    I think this script now works :-)

    function setTestDriveIcon(rowData, userLCID) {

         var str = JSON.parse(rowData);

         var coldata = str.scheduledend_Value;

         var imgName = "";

         var tooltip = "";

         var sub = str.subject;

         if (coldata) {

             var testdrive = sub.includes("testdrive");

             var prøvekjøring = sub.includes("prøvekjøring");

             if (prøvekjøring == true || testdrive == true) {

                 imgName = "mb_testdrive32x32.png";

                 tooltip = "Forventet dato for signering er passert";

             }

         }

         var resultarray = [imgName, tooltip];

         return resultarray;

     }

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